Print Titles and Area

The following example shows how you can set worksheet print titles and print area.

Excel print titles and area set with GemBox.Spreadsheet for Java
Screenshot of 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%");

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.