seamusabshere / xlsx_writer

Writes XLSX files. Simple, clean XML and style. Supports autofilters and headers/footers with images and page numbers if you're willing to do a little Excel hacking.
MIT License
33 stars 10 forks source link

Bad sheet names #10

Closed jxh2 closed 10 years ago

jxh2 commented 10 years ago

Using this to name a sheet:

sheet = doc.add_sheet(:name => "Line #{item.line}" )

… the resulting XLSX file throws an error when opened by MS Excel 2011 Mac, saying "some content is unreadable. Do you want to open and repair this workbook?" Saying yes yields the open workbook, but with the sheet names as "Recovered_Sheet1", etc., for any sheet except the first.

Digging a bit more, xl/workbook.xml contains:

<?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">
  <workbookPr date1904="0" />
  <bookViews>
    <workbookView xWindow="0" yWindow="0" windowWidth="22667" windowHeight="17000" tabRatio="500"/>
  </bookViews>
  <sheets>
    <sheet name="JobSummary" sheetId="1" r:id="rId2"/>
    <sheet name="{:name=&gt;&quot;Line963&quot;}" sheetId="2" r:id="rId3"/>
    <sheet name="{:name=&gt;&quot;Line964&quot;}" sheetId="3" r:id="rId4"/>
    <sheet name="{:name=&gt;&quot;Line1040&quot;}" sheetId="4" r:id="rId5"/>
    <sheet name="{:name=&gt;&quot;Line3322&quot;}" sheetId="5" r:id="rId6"/>  
    <sheet name="{:name=&gt;&quot;Line4516&quot;}" sheetId="6" r:id="rId7"/>
  </sheets>
  <definedNames>
  </definedNames>
</workbook>

Note the extraneous greater-than ( > or amp-gt-semi) in sheets after sheetId=1. Also, the quotes seem to be getting escaped when they should not be.

A new XLSX file created by this Excel does not have the greater-than character or HTML-escapes in the sheet names, for either of two sheets in this test file:

<?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="24030"/><workbookPr showInkAnnotation="0" autoCompressPictures="0"/><bookViews><workbookView xWindow="14520" yWindow="0" windowWidth="25040" windowHeight="17820" tabRatio="500" activeTab="1"/></bookViews><sheets><sheet name="Test Sheet Name 1" sheetId="1" r:id="rId1"/><sheet name="Test Sheet Name 2" sheetId="2" r:id="rId2"/></sheets><calcPr calcId="140000" concurrentCalc="0"/><extLst><ext uri="{7523E5D3-25F3-A5E0-1632-64F254C22452}" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:ArchID Flags="2"/></ext></extLst></workbook>
jxh2 commented 10 years ago

Looking even closer (duh!) all that {:name= … } business doesn't belong there. But it's only broken on sheets after sheet 1.

jxh2 commented 10 years ago

I'm an idiot. Don't pass it a hash.