//create to a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("ManageHeadersOnDifferentPages.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } //create a new workbook Workbook workbook = new Workbook(); workbook.open(this.getResourceStream("xlsx/MultipleHeaders.xlsx")); 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 "B91:F189" is "$91:$91" RepeatSetting repeatSetting2 = new RepeatSetting(); repeatSetting2.setTitleRowStart(88); repeatSetting2.setTitleRowEnd(88); repeatSetting2.setRange(worksheet.getRange("B89:F149")); repeatSettings.add(repeatSetting2); //Create a PrintManager. PrintManager printManager = new PrintManager(); //Get the pagination information of the worksheet. List pages = printManager.paginate(worksheet, null, repeatSettings); //Save the modified pages into pdf file. printManager.savePageInfosToPDF(outputStream, pages); //close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
//create to a pdf file stream var outputStream: FileOutputStream? = null try { outputStream = FileOutputStream("ManageHeadersOnDifferentPages.pdf") } catch (e: FileNotFoundException) { e.printStackTrace() } //create a new workbook var workbook = Workbook() workbook.open(this.getResourceStream("xlsx/MultipleHeaders.xlsx")!!) val worksheet = workbook.worksheets.get(0) val repeatSettings = ArrayList() //The title rows of the "B2:F87" is "$2:$2" val repeatSetting = RepeatSetting() repeatSetting.titleRowStart = 1 repeatSetting.titleRowEnd = 1 repeatSetting.range = worksheet.getRange("B2:F87") repeatSettings.add(repeatSetting) //The title rows of the "B91:F189" is "$91:$91" val repeatSetting2 = RepeatSetting() repeatSetting2.titleRowStart = 88 repeatSetting2.titleRowEnd = 88 repeatSetting2.range = worksheet.getRange("B89:F149") repeatSettings.add(repeatSetting2) //Create a PrintManager. val printManager = PrintManager() //Get the pagination information of the worksheet. val pages = printManager.paginate(worksheet, null, repeatSettings) //Save the modified pages into pdf file. printManager.savePageInfosToPDF(outputStream, pages) //close the file stream try { if(outputStream != null){ outputStream.close() } } catch (e: IOException) { e.printStackTrace() }