If you look at the XML files of a axlsx
document versus the XML files of a standard Excel workbook you'll see that they a bit different. I think RubyXL
is not parsing the workbook properly since the workbook is missing some nodes/attributes that a normal Excel file would have:
workbook.xml (normal Excel version)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="9303"/>
<workbookPr defaultThemeVersion="124226"/>
<bookViews>
<workbookView xWindow="870" yWindow="840" windowWidth="22455" windowHeight="9630"/>
</bookViews>
<sheets>
<sheet name="My Sheet1" sheetId="1" r:id="rId1"/>
<sheet name="My Sheet 2" sheetId="2" r:id="rId2"/>
</sheets>
<calcPr calcId="0"/>
</workbook>
workbook.xml (axlsx version)
<?xml version="1.0" encoding="UTF-8"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<workbookPr date1904="false"/>
<sheets>
<sheet name="My Sheet1" sheetId="1" r:id="rId1"/>
<sheet name="My Sheet 2" sheetId="2" r:id="rId2"/>
</sheets>
</workbook>
If you parse the document with the Ruby standard library win32ole
, it gives the correct worksheet names, so this must be an issue with the way RubyXL is parsing the document.
require 'win32ole'
ex = WIN32OLE.new("Excel.Application")
wb = ex.workbooks.open("simple.xlsx")
wb.worksheets.each do |ws|
puts ws.name
end
Output:
My Sheet1
My Sheet 2
=> nil