Rendering spreadsheets by page breaks
When printing spreadsheets with a lot of data sheets are automatically broken into pages to fit the paper size and keep printed content readable. To preview the page breaks in Excel navigate to View
and click Page Break Preview
as it shown on the screenshot.
In case you print the workbook by clicking at File > Print
and there would be two pages in the print preview.
To perform the same action programmatically with GroupDocs.Viewer set SpreadsheetOptions
to SpreadsheetOptions.forRenderingByPageBreaks()
and call view() method. Let’s take page-breaks.xlsx and render it to PDF by running the following code.
try (Viewer viewer = new Viewer("page-breaks.xlsx")) {
PdfViewOptions viewOptions = new PdfViewOptions();
viewOptions.setSpreadsheetOptions(SpreadsheetOptions.forRenderingByPageBreaks());
// Enable rendering gird lines and headings to check that proper areas are rendered
viewOptions.getSpreadsheetOptions().setRenderGridLines(true);
viewOptions.getSpreadsheetOptions().setRenderHeadings(true);
viewer.view(viewOptions);
}
We’ll get one PDF file with two pages that are corresponds to pages highlighted by Excel on the first screenshot.
The same applies when rendering to HTML, JPEG, and PNG formats.