lib/rubyXL/objects/root.rb in rubyXL-3.2.7 vs lib/rubyXL/objects/root.rb in rubyXL-3.3.0
- old
+ new
@@ -57,17 +57,31 @@
def xlsx_path
OOXMLTopLevelObject::ROOT
end
- def self.parse_file(xl_file_path, opts)
+ def self.parse_file(xl_file_path, opts = {})
begin
::Zip::File.open(xl_file_path) { |zip_file|
root = self.new
root.filepath = xl_file_path
root.content_types = RubyXL::ContentTypes.parse_file(zip_file, ContentTypes::XLSX_PATH)
root.load_relationships(zip_file, OOXMLTopLevelObject::ROOT)
- root.workbook.root = root
+
+ wb = root.workbook
+ wb.root = root
+
+ wb.sheets.each_with_index { |sheet, i|
+ sheet_obj = wb.relationship_container.related_files[sheet.r_id]
+
+ wb.worksheets[i] = sheet_obj # Must be done first so the sheet becomes aware of its number
+ sheet_obj.workbook = wb
+
+ sheet_obj.sheet_name = sheet.name
+ sheet_obj.sheet_id = sheet.sheet_id
+ sheet_obj.state = sheet.state
+ }
+
root
}
rescue ::Zip::Error => e
raise e, "XLSX file format error: #{e}", e.backtrace
end