// Create a new workbook Workbook workbook = new Workbook(); //Load template file Monthly business budget.xlsx from resource InputStream fileStream = this.getResourceStream("xlsx\\Monthly business budget.xlsx"); workbook.open(fileStream); IWorksheet worksheet = workbook.getActiveSheet(); // change chart type to column stacked IChart chart = worksheet.getShapes().get(0).getChart(); chart.setChartType(ChartType.ColumnStacked); chart.getColumnGroups().get(0).setOverlap(100); // set font size for chart title chart.getChartTitle().setText("ESTIMATED v/s ACTUAL BUDGET"); chart.getChartTitle().getFont().setSize(14); chart.getChartTitle().getFont().setName("Calibri"); // config chart area line, font and color chart.getChartArea().getFormat().getFill().getColor().setRGB(Color.GetWhite()); chart.getChartArea().getFont().getColor().setRGB(Color.FromArgb(89, 89, 89)); chart.getChartArea().getFormat().getLine().setVisible(true); chart.getChartArea().getFormat().getLine().getColor().setRGB(Color.FromArgb(217, 217, 217)); // make fill of plot area transparant chart.getPlotArea().getFormat().getFill().setTransparency(1); // config series1 of chart ISeries series1 = chart.getSeriesCollection().get(0); series1.setHasDataLabels(true); series1.getFormat().getLine().setVisible(false); series1.getFormat().getFill().getColor().setRGB(Color.FromArgb(98, 121, 158)); series1.getDataLabels().getFont().getColor().setRGB(Color.FromArgb(64, 64, 64)); // config series2 of chart ISeries series2 = chart.getSeriesCollection().get(1); series2.setHasDataLabels(true); series2.getFormat().getLine().setVisible(false); series2.getFormat().getFill().getColor().setRGB(Color.FromArgb(179, 192, 53)); series2.getDataLabels().getFont().getColor().setRGB(Color.FromArgb(64, 64, 64)); // get the value axis IAxis value_axis = chart.getAxes().item(AxisType.Value, AxisGroup.Primary); // config value_axis of chart value_axis.setHasTitle(true); value_axis.setHasDisplayUnitLabel(false); value_axis.getAxisTitle().setText("AMOUNT (in thousands)"); value_axis.setDisplayUnit(DisplayUnit.Thousands); value_axis.getMajorGridlines().getFormat().getLine().getColor().setRGB(Color.FromArgb(217, 217, 217)); value_axis.setMajorTickMark(TickMark.None); value_axis.getFormat().getLine().setVisible(false); chart.getAxes().item(AxisType.Category).getFormat().getLine().setVisible(false); // Save to an excel file workbook.save("MonthlyBusinessBudget.xlsx");
// Create a new workbook var workbook = Workbook() //Load template file Monthly business budget.xlsx from resource val fileStream = getResourceStream("xlsx\\Monthly business budget.xlsx") workbook.open(fileStream) val worksheet = workbook.activeSheet // change chart type to column stacked val chart = worksheet.shapes[0].chart chart.chartType = ChartType.ColumnStacked chart.columnGroups[0].overlap = 100 // set font size for chart title chart.chartTitle.text = "ESTIMATED v/s ACTUAL BUDGET" chart.chartTitle.font.size = 14.0 chart.chartTitle.font.name = "Calibri" // config chart area line, font and color chart.chartArea.format.fill.color.rgb = Color.GetWhite() chart.chartArea.font.color.rgb = Color.FromArgb(89, 89, 89) chart.chartArea.format.line.visible = true chart.chartArea.format.line.color.rgb = Color.FromArgb(217, 217, 217) // make fill of plot area transparant chart.plotArea.format.fill.transparency = 1.0 // config series1 of chart val series1 = chart.seriesCollection[0] series1.hasDataLabels = true series1.format.line.visible = false series1.format.fill.color.rgb = Color.FromArgb(98, 121, 158) series1.dataLabels.font.color.rgb = Color.FromArgb(64, 64, 64) // config series2 of chart val series2 = chart.seriesCollection[1] series2.hasDataLabels = true series2.format.line.visible = false series2.format.fill.color.rgb = Color.FromArgb(179, 192, 53) series2.dataLabels.font.color.rgb = Color.FromArgb(64, 64, 64) // get the value axis val value_axis = chart.axes.item(AxisType.Value, AxisGroup.Primary) // config value_axis of chart value_axis.hasTitle = true value_axis.hasDisplayUnitLabel = false value_axis.axisTitle.text = "AMOUNT (in thousands)" value_axis.displayUnit = DisplayUnit.Thousands value_axis.majorGridlines.format.line.color.rgb = Color.FromArgb(217, 217, 217) value_axis.majorTickMark = TickMark.None value_axis.format.line.visible = false chart.axes.item(AxisType.Category).format.line.visible = false // Save to an excel file workbook.save("MonthlyBusinessBudget.xlsx")