Rendering print areas

Spreadsheet document allows to set a print area if you want to print a specific section on a worksheet. To set print area in Excel click at Page Layout > Print Area > Set Print Area menu item as it shown on the screenshot below.

Setting print area in Excel

Than you can print the workbook by clicking at File > Print and the print area we selected at the previous step will be printed as it shown in the print preview.

Printing print area in Excel

To perform the same action programmatically with GroupDocs.Viewer set SpreadsheetOptions to SpreadsheetOptions.forRenderingPrintArea() and call view() method. Let’s take monthly-budget.xlsx and render print area by running the following code.

    try (Viewer viewer = new Viewer("monthly-budget.xlsx")) {
        HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();

The Viewer will produce single HTML file with the print area we selected at the beginning.

Rendered print area

The same applies when rendering to PNG, JPG, and PDF formats.