Render 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.

Page break preview in Excel

In case you print the workbook by clicking at File > Print and there would be two pages in the print preview.

Printing spreadsheet in Excel

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.

using (Viewer viewer = new Viewer("page-breaks.xlsx"))
    PdfViewOptions viewOptions = new PdfViewOptions();
    viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForRenderingByPageBreaks();

    // Enable rendering gird lines and headings to check that proper areas are rendered
    viewOptions.SpreadsheetOptions.RenderGridLines = true;
    viewOptions.SpreadsheetOptions.RenderHeadings = true;


We’ll got one PDF file with two pages that are corresponds to pages highlighted by Excel on the first screenshot.

PDF rendered by page breaks

The same applies when rendering to HTML, JPEG, and PNG formats.