// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); Object data = new Object[][]{ {"Name", "City", "Birthday", "Eye color", "Weight", "Height"}, {"Richard", "New York", new GregorianCalendar(1968, 5, 8), "Blue", 67, 165}, {"Nia", "New York", new GregorianCalendar(1972, 6, 3), "Brown", 62, 134}, {"Jared", "New York", new GregorianCalendar(1964, 2, 2), "Hazel", 72, 180}, {"Natalie", "Washington", new GregorianCalendar(1972, 7, 8), "Blue", 66, 163}, {"Damon", "Washington", new GregorianCalendar(1986, 1, 2), "Hazel", 76, 176}, {"Angela", "Washington", new GregorianCalendar(1993, 1, 15), "Brown", 68, 145} }; worksheet.getRange("A1:F7").setValue(data); //iconset rule IIconSetCondition iconset = worksheet.getRange("E2:E7").getFormatConditions().addIconSetCondition(); iconset.setIconSet(workbook.getIconSets().get(IconSetType.Icon3TrafficLights1)); //cell value rule added later, it has the highest priority, set StopIfTrue to true, if cell match condition, it will not apply icon set rule. IFormatCondition cellvalueRule = (IFormatCondition) worksheet.getRange("E2:E7").getFormatConditions().add(FormatConditionType.CellValue, FormatConditionOperator.Between, "66", "70"); cellvalueRule.getFont().setThemeColor(ThemeColor.Accent1); cellvalueRule.setStopIfTrue(true); // Save to an excel file workbook.save("CreateMultiRuleForRange.xlsx");
// Create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) val data = arrayOf(arrayOf("Name", "City", "Birthday", "Eye color", "Weight", "Height"), arrayOf("Richard", "New York", GregorianCalendar(1968, 5, 8), "Blue", 67, 165), arrayOf("Nia", "New York", GregorianCalendar(1972, 6, 3), "Brown", 62, 134), arrayOf("Jared", "New York", GregorianCalendar(1964, 2, 2), "Hazel", 72, 180), arrayOf("Natalie", "Washington", GregorianCalendar(1972, 7, 8), "Blue", 66, 163), arrayOf("Damon", "Washington", GregorianCalendar(1986, 1, 2), "Hazel", 76, 176), arrayOf("Angela", "Washington", GregorianCalendar(1993, 1, 15), "Brown", 68, 145)) worksheet.getRange("A1:F7").value = data //iconset rule val iconset = worksheet.getRange("E2:E7").formatConditions.addIconSetCondition() iconset.iconSet = workbook.iconSets.get(IconSetType.Icon3TrafficLights1) //cell value rule added later, it has the highest priority, set StopIfTrue to true, if cell match condition, it will not apply icon set rule. val cellvalueRule = worksheet.getRange("E2:E7").formatConditions.add(FormatConditionType.CellValue, FormatConditionOperator.Between, "66", "70") as IFormatCondition cellvalueRule.font.themeColor = ThemeColor.Accent1 cellvalueRule.stopIfTrue = true // Save to an excel file workbook.save("CreateMultiRuleForRange.xlsx")