Urgent - Bug: Printing crashes if a sheet contains borders, but no text (index out of range)

Posted by: mantaray on 8 September 2017, 1:07 pm EST

  • Posted 8 September 2017, 1:07 pm EST

    Hi! I believe I have found a bug which is a critical problem for us. We have already released the first version to our customers (today as I write this message), and I just found the problem. I am attaching a test project which demonstrates the problem.

    Creating such pages is not only allowed in our application, but a very likely scenario as our customers will, among other things, use it to create forms, which may indeed contain only borders.

    Best regards,

    <B><SPAN><FONT face=Calibri>PowerOffice AS<o:p></o:p></FONT></SPAN></B>

    <SPAN><FONT face=Calibri>Morten Aune Lyrstad<o:p></o:p></FONT></SPAN>

    <I><SPAN><FONT face=Calibri>Senior Systems Developer<o:p></o:p></FONT></SPAN></I>


  • Replied 8 September 2017, 1:07 pm EST

    Morten -

    I got an exception everytime unless I put some text in a cell, but as I said, by default the spread will not throw an exception if there is no data in the spread.  It will just print a blank page.  You can test this by creating a simple project and calling the FpSpread1.PrintSheet(0).
  • Replied 8 September 2017, 1:07 pm EST

    The issue is not one of borders or no text.  If you comment out these two lines and don't have any text in the spread you will still receive an exception...

    //this.spreadSheet.ActiveSheet.AddSelection(5, 3, 5, 5);

    By default a blank spread would print without throwing an exception but it would print a blank page.  In doing some debugging in your example it looks like there is an invalid page(firstpage, lastpage) count or something to that affect and that variable is outside the index you have set somewhere else.  I would suggest debugging into this further in your printing code.  It does not appear to be a spread issue.
  • Replied 8 September 2017, 1:07 pm EST

    You should also be aware of the fact that even if you have a selection and a border around it in the spread, if you have no text you will still get a blank page when you print.  To see the border there would have to be text in the cells to right and bottom of the border.
  • Replied 8 September 2017, 1:07 pm EST

    Didn't you get an exception when printing this? I do, every time. Howewer, Try to add a single space into the grid. It'll print nicely.

    All "our" printing code is in the "print setup" region in the demo I sent you.

  • Replied 8 September 2017, 1:07 pm EST

    Oh, and I already know about those two lines. They're only there to illustrate the fact that the exception is thrown when there is legal data in the spread, but no text.



  • Replied 8 September 2017, 1:07 pm EST


    There is one problem in your code causing this issue and another problem that may cause an issue later. The first thing is when there is no data, the PrintSheet method of Spread will not print anything. To get the blank page as Bob was stating, you need to set the UseMax property of the PrintInfo structure to False. This will keep the exception from happening.

    The other issue that may come up later based on your code is with the PrintSheet method call itself. Since we print the sheet on a seperate thread, it will be possible for this to print the wrong thing if you are trying to print multiple sheets or make changes to the one sheet between multiple prints. To fix this issue, we have an undocumented method that does the same thing as PrintSheet but prints on the same thread. This method is called SafePrint. I would suggest changing your call to PrintSheet with the following code.

                    <SPAN class=kwd>this</SPAN>.spreadSheet.SafePrint(<SPAN class=kwd>this</SPAN>.spreadSheet, <SPAN class=kwd>this</SPAN>.spreadSheet.Sheets.IndexOf(sheet));
  • Replied 8 September 2017, 1:07 pm EST

    Thank you very much for your help. I believe this may solve several problems I am having.

    If not; is there some way I can do the entire printing myself? Using a PrintDocument, i mean.
  • Replied 8 September 2017, 1:07 pm EST


    There is a method, OwnerPrintDraw, that you can use to control exactly what and how the Spread prints to any Graphics object.

  • Replied 8 September 2017, 1:07 pm EST

    Thank you for your help, I'll have a look.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels