Excel sheet to PDF conversion page division

Hi,

I’m using Aspose.Cells .NET, And I’m having three issues:

  1. When converting an Excel sheet to PDF, the pages are split by the width of the document rather than the height, and the result is that the first few pages are the right side of the document, and the next are the left, instead of what you’d expect (the full width of the row being in the sheet and page breaks between rows). This renders the Excel document virtually unreadable.

  2. If trying to circumvent this issue by using the following code:

         Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf)
         {
             AllColumnsInOnePagePerSheet = true,
             OnePagePerSheet = true
         };
    

Large documents (say a 50000 row excel sheet) create pages that are too big to display in a (non aspose related) viewer.

  1. When running the following code:

         foreach (var worksheet in workbook.Worksheets)
         {
             worksheet.IsGridlinesVisible = true;
             worksheet.IsOutlineShown = true;
             worksheet.VisibilityType = Aspose.Cells.VisibilityType.Visible;
             worksheet.IsRowColumnHeadersVisible = true;
         }
    

There is no grid between the cells in the resulting PDF. I’ve also tried setting the gridline type in the PDF save options.

@YoavLavi,

Thanks for sharing some details.

Well, Aspose.Cells renders Excel worksheets to PDF similar to what is shown when taking the print preview of the sheets in MS Excel manually.

  1. It looks like the Excel file which you are converting to PDF by Aspose.Cells has some PageSetup options set differently for the worksheet(s) (e.g Page Setup|Sheet|Page order - Over, then Down). So, you may try the following line of code:
    e.g
    Sample code:
worksheet.PageSetup.Order = PrintOrderType.DownThenOver;
  1. Sure, if there are lots of rows in the sheet, those options won’t help either. If there are less number of records or pages (of the sheet), then the options would be helpful and will work.

  2. Please try using the following lines of code:
    e.g
    Sample code:

worksheet.PageSetup.PrintGridlines = true;
worksheet.PageSetup.PrintHeadings = true;

Hope, this helps a bit.

1 Like

This works. Thanks!

For anyone reading this - The correct PrintOrderType for what I was trying to do was OverThenDown rather than DownThenOver (just calrifying for anyone trying to do the same).

DownThenOver is “break when you reach a column that would be larger to print than the page width”,
OverThenDown is “break when you reach a row that would be larger to print than the page height”.

This coupled with AllColumnsInOnePagePerSheet = true (and not OnePagePerSheet = true which disables breaking for a sheet completely) did the trick.

@YoavLavi,

Good to know that your issues are sorted out by the suggestions.

Moreover, sure, if you want to print data horizontally (row wise) in sequence, OverThenDown would rightly suit your needs.