Creating printable organized dynamic reports using Aspose.Cells for .NET

we are creating some documents with ASPOSE CELLS for Java. But we are having a hard time organizing this documents in a printable version.

we are creating some reports that writes some data tables with their corresponding headers and some graphic charts created from the information. But when we print the generated document some page breaks are in the middle of a table so the next page appears with no header, or some graphics from the charts are cutted and printed partially.

We are trying to handle this situation by counting the number of rows available in a printable page and when the limit is reached we programmatically add some rows to force a new page then we write manually the header of the table we are writing and continue with the document generation. But if you are using auto adjust properties in some cells the row size is not the same always, also when you are adding charts or external graphics that you don't know the specific size this strategy turns unmanageable.

The generated documents can have some tables with different number of columns and header titles, some charts are generated from those information, and some external images are also added to the document. The result must be in a printable organized version, and ideally able to be exported to PDF maintaining the organization of the printable Excel version.

If you can give some tips for handling this will be very useful. I'm attaching sample source code. The main class is in ReporteVencimientoContratosContratistas.txt class the other classes are dependent classes. I'm attaching the ExpectedPrototype wich is how the report should be generated. I'm attaching what are the generated files resulting from the source code attached.

Hi Alejandro,


First of all, please accept our sincere apologies for a bit delayed response due to the weekend.

I have studied your presented scenario. No doubt it could be difficult to calculate where to put the printing page breaks when you are populating the data dynamically and/or adding the graphs on the fly. Unfortunately, there is no hard n fast rule on how to calculate the page breaks however here a few tips that might help you in achieving your goals.

  1. You can get the printing page breaks of an existing worksheet that will help you understand where the pages will break. You can use the Worksheet.getPrintingPageBreaks method that will return an array of CellsArea which in turn could tell you where the current page breaks are. You can use this information to move the breaks at your desired locations. You can also call the aforesaid method after increasing the height of rows and widths of the columns as well.
  2. You can use the Worksheet.addPageBreaks method or add methods from HorizontalPageBreakCollection & VerticalPageBreakCollection to put the page breaks on the desired locations rather than inserting blank rows. Please check detailed article on managing page breaks.
  3. Instead of inserting the header rows manually, you can use the PageSetup.setPrintTitleRows method to repeat the specified number of rows at the start of each page. For instance, the PageSetup.setPrintTitleRows(“$1:$5”) will insert the first 5 rows on the top of each page, that is; after each horizontal page break.

That being said, if your two spreadsheets ExpectedPrototype.xls & GeneratedReport.xls had the same data, the following piece of code can give the GeneratedReport.xls page breaks identical to ExpectedPrototype.xls. Unfortunately, both spreadsheets have different amount of data and different location of graphs so the following solution isn’t sufficient. However for demonstration purposes, I have provided the code here.

Java

sheet.getHorizontalPageBreaks().clear();
sheet.addPageBreaks(“A45”);
sheet.addPageBreaks(“A78”);
sheet.addPageBreaks(“A98”);