[]
GcExcel允许PDF文件不同页面的重复标题不一样。当PDF文件的每一页上有不同的信息,并且希望PDF文件每一页展示不同的标题时,此功能非常有用。
要为PDF文件中的不同页面配置不同的标题,可以使用setTitleRowStart()方法、setTitleRowEnd()方法和RepeatSetting类的其他方法。完成后,只需创建PrintManager类的实例,使用paginate()方法获取默认分页信息,最后使用savePageInfosToPDF()方法保存并应用设置。
请参阅以下示例代码,以便在导出为PDF文件时导出不同页面上的不同标题。
// Initialize workbook
Workbook workbook = new Workbook();
// Open Excel file
workbook.open("MultipleHeaders.xlsx");
// Fetch default worksheet
IWorksheet worksheet = workbook.getWorksheets().get(0);
List repeatSettings = new ArrayList();
// The title rows of the "B2:F87" is "$2:$2"
RepeatSetting repeatSetting = new RepeatSetting();
repeatSetting.setTitleRowStart(1);
repeatSetting.setTitleRowEnd(1);
repeatSetting.setRange(worksheet.getRange("B2:F87"));
repeatSettings.add(repeatSetting);
// The title rows of the "B89:F146" is "$89:$89"
RepeatSetting repeatSetting2 = new RepeatSetting();
repeatSetting2.setTitleRowStart(88);
repeatSetting2.setTitleRowEnd(88);
repeatSetting2.setRange(worksheet.getRange("B89:F146"));
repeatSettings.add(repeatSetting2);
// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();
worksheet.getPageSetup().setRightMargin(10);
// Get the pagination information of the worksheet
List pages =
printManager.paginate(worksheet, null, repeatSettings);
// Save the modified pages into pdf file
printManager.savePageInfosToPDF("ManageHeadersOnDifferentPages.pdf", pages);