//create a new workbook Workbook workbook = new Workbook(); IWorksheet sheet = workbook.getWorksheets().get(0); //Add Table ITable table = sheet.getTables().add(sheet.getRange("B5:G16"), true); table.setShowTotals(true); //Set values int[] data = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; sheet.getRange("C6:C16").setValue(data); sheet.getRange("D6:D16").setValue(data); //Set total functions table.getColumns().get(1).setTotalsCalculation(TotalsCalculation.Average); table.getColumns().get(2).setTotalsCalculation(TotalsCalculation.Sum); //Create custom table style ITableStyle customTableStyle = workbook.getTableStyles().get("TableStyleMedium10").duplicate(); ITableStyleElement wholeTableStyle = customTableStyle.getTableStyleElements().get(TableStyleElementType.WholeTable); wholeTableStyle.getFont().setItalic(true); wholeTableStyle.getBorders().get(BordersIndex.EdgeTop).setThemeColor(ThemeColor.Accent1); wholeTableStyle.getBorders().get(BordersIndex.EdgeTop).setLineStyle(BorderLineStyle.Thick); wholeTableStyle.getBorders().get(BordersIndex.EdgeRight).setThemeColor(ThemeColor.Accent1); wholeTableStyle.getBorders().get(BordersIndex.EdgeRight).setLineStyle(BorderLineStyle.Thick); wholeTableStyle.getBorders().get(BordersIndex.EdgeBottom).setThemeColor(ThemeColor.Accent1); wholeTableStyle.getBorders().get(BordersIndex.EdgeBottom).setLineStyle(BorderLineStyle.Thick); wholeTableStyle.getBorders().get(BordersIndex.EdgeLeft).setThemeColor(ThemeColor.Accent1); wholeTableStyle.getBorders().get(BordersIndex.EdgeLeft).setLineStyle(BorderLineStyle.Thick); ITableStyleElement firstRowStripStyle = customTableStyle.getTableStyleElements().get(TableStyleElementType.FirstRowStripe); firstRowStripStyle.getFont().setBold(true); //Apply custom style to table table.setTableStyle(customTableStyle); //save to an pdf file workbook.save("SaveTable.pdf");
//create a new workbook var workbook = Workbook() val sheet = workbook.worksheets.get(0) //Add Table val table = sheet.tables.add(sheet.getRange("B5:G16"), true) table.showTotals = true //Set values val data = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) sheet.getRange("C6:C16").value = data sheet.getRange("D6:D16").value = data //Set total functions table.columns.get(1).totalsCalculation = TotalsCalculation.Average table.columns.get(2).totalsCalculation = TotalsCalculation.Sum //Create custom table style val customTableStyle = workbook.tableStyles.get("TableStyleMedium10").duplicate() val wholeTableStyle = customTableStyle.tableStyleElements.get(TableStyleElementType.WholeTable) wholeTableStyle.font.italic = true wholeTableStyle.borders.get(BordersIndex.EdgeTop).themeColor = ThemeColor.Accent1 wholeTableStyle.borders.get(BordersIndex.EdgeTop).lineStyle = BorderLineStyle.Thick wholeTableStyle.borders.get(BordersIndex.EdgeRight).themeColor = ThemeColor.Accent1 wholeTableStyle.borders.get(BordersIndex.EdgeRight).lineStyle = BorderLineStyle.Thick wholeTableStyle.borders.get(BordersIndex.EdgeBottom).themeColor = ThemeColor.Accent1 wholeTableStyle.borders.get(BordersIndex.EdgeBottom).lineStyle = BorderLineStyle.Thick wholeTableStyle.borders.get(BordersIndex.EdgeLeft).themeColor = ThemeColor.Accent1 wholeTableStyle.borders.get(BordersIndex.EdgeLeft).lineStyle = BorderLineStyle.Thick val firstRowStripStyle = customTableStyle.tableStyleElements.get(TableStyleElementType.FirstRowStripe) firstRowStripStyle.font.bold = true //Apply custom style to table table.tableStyle = customTableStyle //save to an pdf file workbook.save("SaveTable.pdf")