Print Titles and Area

Following example demonstrates how to set worksheet print titles and print area.

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

class Program {

    public static void main(String[] args) throws {
        // If using Professional version, put your serial key below.

        ExcelFile workbook = new ExcelFile();

        // Always print 1st row.
        ExcelWorksheet worksheet1 = workbook.addWorksheet("Sheet1");
        worksheet1.getNamedRanges().setPrintTitles(worksheet1.getRow(0), 1);

        // Set print area (from A1 to I120):
        worksheet1.getNamedRanges().setPrintArea(worksheet1.getCells().getSubrange("A1", "I120"));

        // Always print columns from A to F.
        ExcelWorksheet worksheet2 = workbook.addWorksheet("Sheet2");
        worksheet2.getNamedRanges().setPrintTitles(worksheet2.getColumn(0), 6);

        // Always print columns from A to F and first row.
        ExcelWorksheet worksheet3 = workbook.addWorksheet("Sheet3");
        worksheet3.getNamedRanges().setPrintTitles(worksheet3.getRow(0), 1, worksheet3.getColumn(0), 6);

        // Fill Sheet1 with some data
        for (int i = 0; i < 9; i++)
            worksheet1.getCell(0, i).setValue("Column " + ExcelColumnCollection.columnIndexToName(i));

        for (int i = 1; i < 120; i++)
            for (int j = 0; j < 9; j++)
                worksheet1.getCell(i, j).setValue(i + j);"Print Titles and Area.%OutputFileType%");

Check next example or download examples from GitHub.