// Create a new workbook Workbook workbook = new Workbook(); Object data = new Object[][] { {"Number", "Date", "Customer", "Description", "Trend", "0-30 Days", "30-60 Days", "60-90 Days", ">90 Days", "Amount"}, {"1001", new GregorianCalendar(2017, 4, 21), "Customer A", "Invoice 1001", null, 1200.15, 1916.18, 1105.23, 1806.53, null}, {"1002", new GregorianCalendar(2017, 2, 18), "Customer B", "Invoice 1002", null, 896.23, 1005.53, 1800.56, 1150.49, null}, {"1003", new GregorianCalendar(2017, 5, 15), "Customer C", "Invoice 1003", null, 827.63, 1009.23, 1869.23, 1002.56, null} }; IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getRange("B2:K5").setValue(data); worksheet.getRange("B:K").setColumnWidth(15); worksheet.getTables().add(worksheet.getRange("B2:K5"), true); worksheet.getTables().get(0).getColumns().get(9).getDataBodyRange().setFormula("=SUM(Table1[@[0-30 Days]:[>90 Days]])"); //create a new group of sparklines. worksheet.getRange("F3").getSparklineGroups().add(SparkType.Line, "G3:J3"); //create another new group of sparklines. worksheet.getRange("F4:F5").getSparklineGroups().add(SparkType.Column, "G4:J5"); //clear F3 and F4 cell's sparkline. F5 cell's sparkline still exist. worksheet.getRange("F3, F4").getSparklineGroups().clear(); // Save to an excel file workbook.save("ClearSparklines.xlsx");
// Create a new workbook var workbook = Workbook() val data = arrayOf(arrayOf("Number", "Date", "Customer", "Description", "Trend", "0-30 Days", "30-60 Days", "60-90 Days", ">90 Days", "Amount"), arrayOf("1001", GregorianCalendar(2017, 4, 21), "Customer A", "Invoice 1001", null, 1200.15, 1916.18, 1105.23, 1806.53, null), arrayOf("1002", GregorianCalendar(2017, 2, 18), "Customer B", "Invoice 1002", null, 896.23, 1005.53, 1800.56, 1150.49, null), arrayOf("1003", GregorianCalendar(2017, 5, 15), "Customer C", "Invoice 1003", null, 827.63, 1009.23, 1869.23, 1002.56, null)) val worksheet = workbook.worksheets.get(0) worksheet.getRange("B2:K5").value = data worksheet.getRange("B:K").columnWidth = 15.0 worksheet.tables.add(worksheet.getRange("B2:K5"), true) worksheet.tables.get(0).columns.get(9).dataBodyRange.formula = "=SUM(Table1[@[0-30 Days]:[>90 Days]])" //create a new group of sparklines. worksheet.getRange("F3").sparklineGroups.add(SparkType.Line, "G3:J3") //create another new group of sparklines. worksheet.getRange("F4:F5").sparklineGroups.add(SparkType.Column, "G4:J5") //clear F3 and F4 cell's sparkline. F5 cell's sparkline still exist. worksheet.getRange("F3, F4").sparklineGroups.clear() // Save to an excel file workbook.save("ClearSparklines.xlsx")