protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
826 stars 416 forks source link

Print with MS Excel 2013 #32

Open Ajolos opened 8 years ago

Ajolos commented 8 years ago

Hello. I have tested this library (beta branch) and I faced a problem with printing downloaded file - when I try to do it with MS Excel (2013), it simply crashes. The problem doesn't exist in Libre Office Calc, and vanishes, when I save the file as a new one, and reopen.

I hope you can see the problem in those files: The one, that was downloaded with this library: downloaded_file.xlsx - MS Excel crashes, when I try to print it. And the second one, created through saving downloaded file once again: resaved_file.xlsx - MS Excel prints document perfectly

Ajolos commented 8 years ago

I found that the problem is generated by sheetViews node in worksheets/sheet1.xml file. When I comment out the lines that append this node to output file, everything seems to work just fine.

pietersv commented 8 years ago

@Ajolos Thank you for reporting this. I'm able to print fine in OSX Office 2011. Not a comprehensive test but i can run that quickly. Differencing the downloaded and saved files, the difference in that section is the saved file does not have the attribute showGridlines="1". It seems that "1" is the assumed value if not specified and should not be in the XML.

Can you try commenting out line xlsx.js:7843 (or 67_bits.js:311 then make) and tell me if the problem persists?

showGridLines: opts.showGridLines == false ? '0' : '1',

Ajolos commented 8 years ago

Well, commenting out the line you pointed didn't change anything - Excel still crashes after pressing 'Print'. However, when I comment out the next line tabSelected: opts.tabSelected === undefined ? '1' : opts.tabSelected, (node sheetView in output file has no attribute tabSelected) or change its default value to '0' tabSelected: opts.tabSelected === undefined ? '0' : opts.tabSelected, (node sheetView in output file has attribute tabSelected="0") I can print the file successfully. Does it make any sense to you? So far I found the tabSelected attribute definition:

Flag indicating whether this sheet is selected. When only 1 sheet is selected and active, this value should be in synch with the activeTab value. In case of a conflict, the Start Part setting wins and sets the active sheet tab.

I didn't debug the whole library, but in the source code activeTab is mentioned only once - in line 8352: var WBViewDef = [ ['activeTab', '0'], ... //window{Height,Width}, {x,y}Window ];

It seems like the activeTab is set to '0' by default, but tabSelected is set to '1', which is in conflict with the definition (should be in sync).

pietersv commented 8 years ago

This is great. Working into next release.

knownasilya commented 8 years ago

Same as #29? Will test 0.8.13 and let you know tomorrow if it fixed my issue.