//create a new workbook Workbook workbook = new Workbook(); //Add one custom table style. ITableStyle style = workbook.getTableStyles().add("test"); //Set WholeTable element style. style.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setItalic(true); style.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setColor(Color.GetWhite()); style.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setStrikethrough(true); style.getTableStyleElements().get(TableStyleElementType.WholeTable).getBorders().setLineStyle(BorderLineStyle.Dotted); style.getTableStyleElements().get(TableStyleElementType.WholeTable).getBorders().setColor(Color.FromArgb(0, 193, 213)); style.getTableStyleElements().get(TableStyleElementType.WholeTable).getInterior().setColor(Color.FromArgb(59, 92, 170)); //Set FirstColumnStripe element style. style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getFont().setBold(true); style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getFont().setColor(Color.FromArgb(255, 0, 0)); style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getBorders().setLineStyle(BorderLineStyle.Thick); style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getBorders().setThemeColor(ThemeColor.Accent5); style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getInterior().setColor(Color.FromArgb(255, 255, 0)); style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).setStripeSize(2); //Set SecondColumnStripe element style. style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getFont().setColor(Color.FromArgb(255, 0, 255)); style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getBorders().setLineStyle(BorderLineStyle.DashDot); style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getBorders().setColor(Color.FromArgb(42, 105, 162)); style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getInterior().setColor(Color.FromArgb(204, 204, 255)); //add table. IWorksheet worksheet = workbook.getWorksheets().get(0); ITable table = worksheet.getTables().add(worksheet.getRange("A1:F7"), true); worksheet.getRange("A:F").setColumnWidth(15); //set custom table style to table. table.setTableStyle(style); //save to an excel file workbook.save("AddCustomTableStyle.xlsx");
//create a new workbook var workbook = Workbook() //Add one custom table style. val style = workbook.tableStyles.add("test") //Set WholeTable element style. style.tableStyleElements.get(TableStyleElementType.WholeTable).font.italic = true style.tableStyleElements.get(TableStyleElementType.WholeTable).font.color = Color.GetWhite() style.tableStyleElements.get(TableStyleElementType.WholeTable).font.strikethrough = true style.tableStyleElements.get(TableStyleElementType.WholeTable).borders.lineStyle = BorderLineStyle.Dotted style.tableStyleElements.get(TableStyleElementType.WholeTable).borders.color = Color.FromArgb(0, 193, 213) style.tableStyleElements.get(TableStyleElementType.WholeTable).interior.color = Color.FromArgb(59, 92, 170) //Set FirstColumnStripe element style. style.tableStyleElements.get(TableStyleElementType.FirstColumnStripe).font.bold = true style.tableStyleElements.get(TableStyleElementType.FirstColumnStripe).font.color = Color.FromArgb(255, 0, 0) style.tableStyleElements.get(TableStyleElementType.FirstColumnStripe).borders.lineStyle = BorderLineStyle.Thick style.tableStyleElements.get(TableStyleElementType.FirstColumnStripe).borders.themeColor = ThemeColor.Accent5 style.tableStyleElements.get(TableStyleElementType.FirstColumnStripe).interior.color = Color.FromArgb(255, 255, 0) style.tableStyleElements.get(TableStyleElementType.FirstColumnStripe).stripeSize = 2 //Set SecondColumnStripe element style. style.tableStyleElements.get(TableStyleElementType.SecondColumnStripe).font.color = Color.FromArgb(255, 0, 255) style.tableStyleElements.get(TableStyleElementType.SecondColumnStripe).borders.lineStyle = BorderLineStyle.DashDot style.tableStyleElements.get(TableStyleElementType.SecondColumnStripe).borders.color = Color.FromArgb(42, 105, 162) style.tableStyleElements.get(TableStyleElementType.SecondColumnStripe).interior.color = Color.FromArgb(204, 204, 255) //add table. val worksheet = workbook.worksheets.get(0) val table = worksheet.tables.add(worksheet.getRange("A1:F7"), true) worksheet.getRange("A:F").columnWidth = 15.0 //set custom table style to table. table.tableStyle = style //save to an excel file workbook.save("AddCustomTableStyle.xlsx")