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 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%");
    }
}

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.