// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getRange("C2").setValue("Unit:"); worksheet.getRange("D2").setValue("USD"); worksheet.getRange("C4:D4").merge(); worksheet.getRange("C4:D4").setValue("FY 2019"); worksheet.getRange("C5:D5").merge(); worksheet.getRange("C5:D5").setValue("Sales"); worksheet.getRange("C6").setValue("Monthly"); worksheet.getRange("D6").setValue("Cumulative"); String[] months = { "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar" }; int[] monthlySales = { 188897, 208146, 226196, 277318, 263273, 259845, 241047, 256306, 195845, 204934, 257852, 227779 }; for (int i = 0; i < months.length; i++) { worksheet.getRange("B" + (7 + i)).setValue(months[i]); worksheet.getRange("C" + (7 + i)).setValue(monthlySales[i]); worksheet.getRange("D" + (7 + i)).setFormula("=SUM($C$7:C" + (7 + i) + ")"); } // Set color using string worksheet.getRange("D2").getInterior().setColor(ColorUtilities.stringToColor("yellow")); worksheet.getRange("D2").getBorders().setColor(ColorUtilities.stringToColor("black")); worksheet.getRange("B4:D6").getInterior().setColor(ColorUtilities.stringToColor("#ADD8E6")); worksheet.getRange("C4:D6").getBorders().setColor(ColorUtilities.stringToColor("#000000FF")); worksheet.getRange("B7:B18").getInterior().setColor(ColorUtilities.stringToColor("rgb(211,211,211)")); worksheet.getRange("B7:D18").getBorders().setColor(ColorUtilities.stringToColor("rgba(0,0,0,1)")); worksheet.getRange("B4:B6").getBorders().get(BordersIndex.EdgeLeft).setLineStyle(BorderLineStyle.Thin); worksheet.getRange("B4:B6").getBorders().get(BordersIndex.EdgeTop).setLineStyle(BorderLineStyle.Thin); worksheet.getRange("B4:B6").merge(); worksheet.getRange("C2:D18").setColumnWidth(15); worksheet.getRange("B2:D18").setHorizontalAlignment(HorizontalAlignment.Center); worksheet.getRange("B2:D18").setVerticalAlignment(VerticalAlignment.Center); worksheet.getRange("B4:D6").getFont().setBold(true); worksheet.getRange("C7:D18").setNumberFormat("#,##0"); worksheet.getRange("C2").setHorizontalAlignment(HorizontalAlignment.Right); // Save to an excel file workbook.save("SetColorUsingString.xlsx");