// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.setName("Horizontal"); worksheet.getRange("A1").setValue("A salesman's incomings and outgoings"); worksheet.getRange("A2:B8").setValue(new Object[][]{ {"Salary", 3500}, {"Performance pay", 2500}, {"Pay for customers", -1000}, {"Board expenses", -1000}, {"Chummage", -900}, {"Financial management", 300}, {"Deposit", 3400} }); worksheet.getRange("1:11").setRowHeight(20); worksheet.getRange("A1").setColumnWidth(20); worksheet.getRange("B1").setColumnWidth(15); worksheet.getRange("C1").setColumnWidth(40); worksheet.getRange("A1:C1").merge(); worksheet.getRange("A1").setHorizontalAlignment(HorizontalAlignment.Center); worksheet.getRange("A1").getInterior().setColor(Color.GetPurple()); worksheet.getRange("A1").getFont().setColor(Color.GetWhite()); worksheet.getRange("A1").getFont().setSize(15); worksheet.getRange("A1").getFont().setBold(true); // Add a cascade sparkline with horizontal bars. for (int i = 1; i < 8; i++) { worksheet.getRange(i, 2).setFormula("=CASCADESPARKLINE(B2:B8, ROW() - 1, A2:A8, , , \"#8CBF64\", \"#D6604D\", FALSE)"); } IWorksheet worksheet_vertical = workbook.getWorksheets().add(); worksheet_vertical.setName("Vertical"); worksheet_vertical.getRange("A1").setValue("Inventory Audit"); worksheet_vertical.getRange("A2:E3").setValue(new Object[][]{ {"Stock", "Damaged", "Refurbished", "Returns", "Salable Units"}, {790, -220, 170, 83, 823} }); worksheet_vertical.getRange("A1:E1").merge(); worksheet_vertical.getRange("A1").setHorizontalAlignment(HorizontalAlignment.Center); worksheet_vertical.getRange("A1").getInterior().setColor(Color.GetGray()); worksheet_vertical.getRange("A1").getFont().setColor(Color.GetWhite()); worksheet_vertical.getRange("A1").getFont().setSize(15); worksheet_vertical.getRange("A1:A3").getFont().setBold(true); worksheet_vertical.getRange("E2:E3").getFont().setBold(true); worksheet_vertical.getRange("1:1").setRowHeight(20); worksheet_vertical.getRange("4:4").setRowHeight(200); worksheet_vertical.getRange("A:E").setColumnWidth(14); // Add a cascade sparkline with vertical bars. for (int i = 0; i < 5; i++) { worksheet_vertical.getRange(3, i).setFormula("=CASCADESPARKLINE($A$3:$E$3, COLUMN(), $A$2:$E$2, , , \"#8CBF64\", \"#D6604D\", true)"); } // Save to a pdf file workbook.save("CascadeSparkline.pdf");