/
AsposePrintTitles.java
38 lines (29 loc) · 1.28 KB
/
AsposePrintTitles.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.aspose.cells.examples.asposefeatures.print;
import com.aspose.cells.FileFormatType;
import com.aspose.cells.PageSetup;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.cells.WorksheetCollection;
import com.aspose.cells.examples.Utils;
public class AsposePrintTitles
{
public static void main(String[] args) throws Exception
{
// The path to the documents directory.
String dataDir = Utils.getDataDir(AsposePrintTitles.class);
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the first worksheet in the Workbook file
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
//Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
//Defining column numbers A & B as title columns
pageSetup.setPrintTitleColumns("$A:$B");
//Defining row numbers 1 & 2 as title rows
pageSetup.setPrintTitleRows("$1:$2");
// Workbooks can be saved in many formats
workbook.save(dataDir + "AsposePrintTitles.xlsx", FileFormatType.XLSX);
System.out.println("Print Titles Set successfully."); // Print Message
}
}