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

Lower camel-case xl/sharedStrings.xml leads to blank strings #12

Closed rcook closed 10 years ago

rcook commented 10 years ago

Repro case:

require 'fileutils'
require 'xlsx_writer'

workbook = XlsxWriter.new
worksheet = workbook.add_sheet('Foo')
worksheet.add_row(['hello', 'world'])
FileUtils.mv workbook.path, 'bar.xlsx'
workbook.cleanup

With xlsx_writer 0.4.1, this generates a valid XLSX containing the sheet "Foo" which contains the strings "hello" and "world".

With xlsx_writer 0.4.3, this generates a valid XLSX containing the sheet "Foo" which contains no strings.

This regression was introduced in commit 0a28c61bee572f54c2dc18ec3608fd0784967dd4.

This is caused by storing the shared strings in xl/sharedStrings.xml (lower camel-case) instead of xl/sharedstrings.xml (lower-case).

I think the correct fix is one of the following:

<Override PartName="/xl/sharedstrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>

to

<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>

I don't know if this is significant, but I'm running on a case-sensitive file system (EXT2 on Ubuntu) and using LibreOffice to view the XLSX files. It's possible that Excel proper is more permissive and does not choke when the file name cases differ like this. This might explain why this issue hasn't been reported previously.