Print and View Options

Following example shows how to specify worksheet print and view options.

Excel print and view options set with GemBox.Spreadsheet for Java
Screenshot of Excel print and view options set with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using the Professional version, put your serial key below.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Print and View Options");

        worksheet.getCell("M1").setValue("This worksheet shows how to set various print related and view related options.");
        worksheet.getCell("M2").setValue("To see results of print options, go to Print and Page Setup dialogs in MS Excel.");
        worksheet.getCell("M3").setValue("Notice that print and view options are worksheet based, not workbook based.");

        // Print options:
        ExcelPrintOptions printOptions = worksheet.getPrintOptions();
        printOptions.setPrintGridlines(true);
        printOptions.setPrintHeadings(true);
        printOptions.setPortrait(false);
        printOptions.setPaperType(PaperType.A3);
        printOptions.setNumberOfCopies(5);

        // View options:
        worksheet.getViewOptions().setFirstVisibleColumn(3);
        worksheet.getViewOptions().setShowColumnsFromRightToLeft(true);
        worksheet.getViewOptions().setZoom(123);

        // Set print area
        worksheet.getNamedRanges().setPrintArea(worksheet.getCells().getSubrange("E1", "U7"));

        workbook.save("Print and View Options.%OutputFileType%");
    }
}

See also


Next steps

GemBox.Spreadsheet for Java is a component that enables you to read, write, edit and convert spreadsheet files from your applications using one simple API.

Download Buy