Page 1 of 1

Excel crash if i try to print the generated File

PostPosted: Thu Feb 13, 2014 9:01 pm
by Nadeo
Hi,

I have generated
test.xlsx
Not Printable xlsx-File.
(3.18 KiB) Downloaded 419 times
with xlsx4j , but if I try to print it, Excel crashes and restarts. This is the Error message without information :
printError.png
Excel Error Message
printError.png (18.17 KiB) Viewed 2381 times



What did I do wrong?

Regards, Nadeo

Re: Excel crash if i try to print the generated File

PostPosted: Mon Feb 17, 2014 11:06 am
by jason
It crashes for me too.

Please find attached a fixed version (which Excel 2010 x64 can open / print OK).

You can compare the 2 files to determine the important difference, then mimic that. Please let us know what you find out!

Re: Excel crash if i try to print the generated File

PostPosted: Mon Feb 17, 2014 9:08 pm
by Nadeo
Thanks for the first try.

I have compared the two files and the result is that all Files inside are different from the Original "test.xlsx" :
result.PNG
result.PNG (34.14 KiB) Viewed 2367 times


I begin now to search important differences.

Re: Excel crash if i try to print the generated File

PostPosted: Mon Feb 17, 2014 9:33 pm
by jason
The OpenXMLDiff tool referred to in http://stackoverflow.com/questions/4224 ... -documents might help a bit ...

Re: Excel crash if i try to print the generated File

PostPosted: Mon Feb 17, 2014 11:10 pm
by Nadeo
I have found the Problem:

Without this Part, the Printer-Driver can`t find the Right "View" :
/xl/workbook.xml:

Code: Select all
<bookViews>
   <workbookView xWindow="510" yWindow="510" windowWidth="11175" windowHeight="9915"/>
</bookViews>


To add it I have do this:

Code: Select all
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
      workBook = pkg.getWorkbookPart();

      // OF = "ObjectFactory OF = Context.getsmlObjectFactory();"
      Workbook wb = OF.createWorkbook();
      BookViews bookview = OF.createBookViews();
      CTBookView ctBookview = OF.createCTBookView();
      ctBookview.setXWindow(510);
      ctBookview.setYWindow(510);
      ctBookview.setWindowWidth(11175L);
      ctBookview.setWindowHeight(9915L);
      bookview.getWorkbookView().add(ctBookview);
      wb.setBookViews(bookview);
      // without this, there will be an "nullPointerException" in :
      // SpreadsheetMLPackage
      // _____createWorksheetPart([...])
      // _________sheets.getSheet().add(s); <<--sheets is null without the next line
      wb.setSheets(OF.createSheets());
      workBook.setJaxbElement(wb);   



@jason:
to Compare XML I use the "Compare"-Plugin from Notepad++ in combination with "XML Tools"-Plugin .

Thanks for Help!!!

Thread can be closed.

Re: Excel crash if i try to print the generated File

PostPosted: Tue Feb 18, 2014 10:08 am
by jason
Thanks for your great detective work :-)

Based on http://social.msdn.microsoft.com/Forums ... um=oxmlsdk
I have added:

https://github.com/plutext/docx4j/commi ... bb4d8149c5

So you won't need to do this yourself.

Curiously, without this it seems to only fail to print on some worksheets, not others. I think it is OK if you have content in cell A1, but not otherwise - something like that.