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

using (Viewer viewer = new Viewer("monthly-budget.xlsx"))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
    viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForRenderingPrintArea();

    viewer.View(viewOptions);
}

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.

More resources

View Excel Files Online

Along with full-featured .NET library we provide simple but powerful free online Apps. View Excel XLS, XLSX, and XLSB files online with GroupDocs Viewer App.

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples: