shadeBands(wb.createSheet("Shade Bands"));\r
iconSets(wb.createSheet("Icon Sets"));\r
colourScales(wb.createSheet("Colour Scales"));\r
- \r
- // TODO Add data bars, see bug #58130\r
+ dataBars(wb.createSheet("Data Bars"));\r
\r
// Write the output to a file\r
String file = "cf-poi.xls";\r
((ExtendedColor)cs3.getColors()[1]).setARGBHex("FF63BE7B");\r
sheetCF.addConditionalFormatting(regions, rule3);\r
}\r
+ \r
+ /**\r
+ * DataBars / Data-Bars allow you to have bars shown vary\r
+ * based on the values, from full to empty\r
+ */\r
+ static void dataBars(Sheet sheet) {\r
+ sheet.createRow(0).createCell(0).setCellValue("Data Bars");\r
+ Row r = sheet.createRow(1);\r
+ r.createCell(1).setCellValue("Green Positive");\r
+ r.createCell(2).setCellValue("Blue Mix");\r
+ r.createCell(3).setCellValue("Red Negative");\r
+ r = sheet.createRow(2);\r
+ r.createCell(1).setCellValue(0);\r
+ r.createCell(2).setCellValue(0);\r
+ r.createCell(3).setCellValue(0);\r
+ r = sheet.createRow(3);\r
+ r.createCell(1).setCellValue(5);\r
+ r.createCell(2).setCellValue(-5);\r
+ r.createCell(3).setCellValue(-5);\r
+ r = sheet.createRow(4);\r
+ r.createCell(1).setCellValue(10);\r
+ r.createCell(2).setCellValue(10);\r
+ r.createCell(3).setCellValue(-10);\r
+ r = sheet.createRow(5);\r
+ r.createCell(1).setCellValue(5);\r
+ r.createCell(2).setCellValue(5);\r
+ r.createCell(3).setCellValue(-5);\r
+ r = sheet.createRow(6);\r
+ r.createCell(1).setCellValue(20);\r
+ r.createCell(2).setCellValue(-10);\r
+ r.createCell(3).setCellValue(-20);\r
+ sheet.setColumnWidth(0, 3000);\r
+ sheet.setColumnWidth(1, 5000);\r
+ sheet.setColumnWidth(2, 5000);\r
+ sheet.setColumnWidth(3, 5000);\r
+\r
+ SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();\r
+ \r
+ ExtendedColor color = sheet.getWorkbook().getCreationHelper().createExtendedColor();\r
+ color.setARGBHex("FF63BE7B");\r
+ CellRangeAddress[] regions = { CellRangeAddress.valueOf("B2:B7") };\r
+ ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(color);\r
+ DataBarFormatting db1 = rule1.getDataBarFormatting();\r
+ db1.getMinThreshold().setRangeType(RangeType.MIN);\r
+ db1.getMaxThreshold().setRangeType(RangeType.MAX);\r
+ sheetCF.addConditionalFormatting(regions, rule1);\r
+ \r
+ color = sheet.getWorkbook().getCreationHelper().createExtendedColor();\r
+ color.setARGBHex("FF5A8AC6");\r
+ regions = new CellRangeAddress[] { CellRangeAddress.valueOf("C2:C7") };\r
+ ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(color);\r
+ DataBarFormatting db2 = rule2.getDataBarFormatting();\r
+ db2.getMinThreshold().setRangeType(RangeType.MIN);\r
+ db2.getMaxThreshold().setRangeType(RangeType.MAX);\r
+ sheetCF.addConditionalFormatting(regions, rule2);\r
+ \r
+ color = sheet.getWorkbook().getCreationHelper().createExtendedColor();\r
+ color.setARGBHex("FFF8696B");\r
+ regions = new CellRangeAddress[] { CellRangeAddress.valueOf("D2:D7") };\r
+ ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingRule(color);\r
+ DataBarFormatting db3 = rule3.getDataBarFormatting();\r
+ db3.getMinThreshold().setRangeType(RangeType.MIN);\r
+ db3.getMaxThreshold().setRangeType(RangeType.MAX);\r
+ sheetCF.addConditionalFormatting(regions, rule3);\r
+ }\r
}\r
}\r
\r
public void testCreateDataBarFormatting() {\r
- // TODO Implement then test\r
+ Workbook workbook = _testDataProvider.createWorkbook();\r
+ Sheet sheet = workbook.createSheet();\r
+\r
+ String colorHex = "FFFFEB84";\r
+ ExtendedColor color = workbook.getCreationHelper().createExtendedColor();\r
+ color.setARGBHex(colorHex);\r
+ SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();\r
+ ConditionalFormattingRule rule1 = \r
+ sheetCF.createConditionalFormattingRule(color);\r
+ DataBarFormatting dbFmt = rule1.getDataBarFormatting();\r
+ \r
+ assertEquals(false, dbFmt.isIconOnly());\r
+ assertEquals(true, dbFmt.isLeftToRight());\r
+ assertEquals(0, dbFmt.getWidthMin());\r
+ assertEquals(100, dbFmt.getWidthMax());\r
+ assertColour(colorHex, dbFmt.getColor());\r
+ \r
+ dbFmt.getMinThreshold().setRangeType(RangeType.MIN);\r
+ dbFmt.getMaxThreshold().setRangeType(RangeType.MAX);\r
+ \r
+ CellRangeAddress [] regions = { CellRangeAddress.valueOf("A1:A5") };\r
+ sheetCF.addConditionalFormatting(regions, rule1);\r
+ \r
+ // Save, re-load and re-check\r
+ workbook = _testDataProvider.writeOutAndReadBack(workbook);\r
+ sheetCF = sheet.getSheetConditionalFormatting();\r
+ assertEquals(1, sheetCF.getNumConditionalFormattings());\r
+ \r
+ ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);\r
+ assertEquals(1, cf.getNumberOfRules());\r
+ rule1 = cf.getRule(0);\r
+ dbFmt = rule1.getDataBarFormatting();\r
+ assertEquals(ConditionType.DATA_BAR, rule1.getConditionTypeType());\r
+ \r
+ assertEquals(false, dbFmt.isIconOnly());\r
+ assertEquals(true, dbFmt.isLeftToRight());\r
+ assertEquals(0, dbFmt.getWidthMin());\r
+ assertEquals(100, dbFmt.getWidthMax());\r
+ assertColour(colorHex, dbFmt.getColor());\r
+\r
+ assertEquals(RangeType.MIN, dbFmt.getMinThreshold().getRangeType());\r
+ assertEquals(RangeType.MAX, dbFmt.getMaxThreshold().getRangeType());\r
+ assertEquals(null, dbFmt.getMinThreshold().getValue());\r
+ assertEquals(null, dbFmt.getMaxThreshold().getValue());\r
}\r
\r
public void testBug55380() {\r