import java.io.IOException;
import org.apache.poi.hssf.HSSFITestDataProvider;
-import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.Test;
/**
assertNotNull(wbBack);
wbBack.close();
}
-
-
- @SuppressWarnings("deprecation")
- @Test
- public void test52122() throws Exception {
- Workbook workbook = new HSSFWorkbook();
- Sheet sheet = workbook.createSheet("Conditional Formatting Test");
- sheet.setColumnWidth(0, 256 * 10);
- sheet.setColumnWidth(1, 256 * 10);
- sheet.setColumnWidth(2, 256 * 10);
-
- // Create some content.
- // row 0
- Row row = sheet.createRow(0);
-
- Cell cell0 = row.createCell(0);
- cell0.setCellType(CellType.NUMERIC);
- cell0.setCellValue(100);
-
- Cell cell1 = row.createCell(1);
- cell1.setCellType(CellType.NUMERIC);
- cell1.setCellValue(120);
-
- Cell cell2 = row.createCell(2);
- cell2.setCellType(CellType.NUMERIC);
- cell2.setCellValue(130);
-
- // row 1
- row = sheet.createRow(1);
-
- cell0 = row.createCell(0);
- cell0.setCellType(CellType.NUMERIC);
- cell0.setCellValue(200);
-
- cell1 = row.createCell(1);
- cell1.setCellType(CellType.NUMERIC);
- cell1.setCellValue(220);
-
- cell2 = row.createCell(2);
- cell2.setCellType(CellType.NUMERIC);
- cell2.setCellValue(230);
-
- // row 2
- row = sheet.createRow(2);
-
- cell0 = row.createCell(0);
- cell0.setCellType(CellType.NUMERIC);
- cell0.setCellValue(300);
-
- cell1 = row.createCell(1);
- cell1.setCellType(CellType.NUMERIC);
- cell1.setCellValue(320);
-
- cell2 = row.createCell(2);
- cell2.setCellType(CellType.NUMERIC);
- cell2.setCellValue(330);
-
- // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank.
- SheetConditionalFormatting formatting = sheet.getSheetConditionalFormatting();
-
- ConditionalFormattingRule rule = formatting.createConditionalFormattingRule("$A$1>75");
-
- PatternFormatting pattern = rule.createPatternFormatting();
- pattern.setFillBackgroundColor(IndexedColors.BLUE.index);
- pattern.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
-
- CellRangeAddress[] range = {CellRangeAddress.valueOf("B2:C2")};
- CellRangeAddress[] range2 = {CellRangeAddress.valueOf("B1:C1")};
-
- formatting.addConditionalFormatting(range, rule);
- formatting.addConditionalFormatting(range2, rule);
-
- // Write file.
- /*FileOutputStream fos = new FileOutputStream("c:\\temp\\52122_conditional-sheet.xls");
- try {
- workbook.write(fos);
- } finally {
- fos.close();
- }*/
-
- Workbook wbBack = HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)workbook);
- Sheet sheetBack = wbBack.getSheetAt(0);
- final SheetConditionalFormatting sheetConditionalFormattingBack = sheetBack.getSheetConditionalFormatting();
- assertNotNull(sheetConditionalFormattingBack);
- final ConditionalFormatting formattingBack = sheetConditionalFormattingBack.getConditionalFormattingAt(0);
- assertNotNull(formattingBack);
- final ConditionalFormattingRule ruleBack = formattingBack.getRule(0);
- assertNotNull(ruleBack);
- final PatternFormatting patternFormattingBack1 = ruleBack.getPatternFormatting();
- assertNotNull(patternFormattingBack1);
- assertEquals(IndexedColors.BLUE.index, patternFormattingBack1.getFillBackgroundColor());
- assertEquals(PatternFormatting.SOLID_FOREGROUND, patternFormattingBack1.getFillPattern());
- }
}
assertEquals(2, wb.getNumberOfSheets());\r
} catch (RuntimeException e) {\r
if (e.getMessage().indexOf("needs to define a clone method") > 0) {\r
- fail("Indentified bug 45682");\r
+ fail("Identified bug 45682");\r
}\r
throw e;\r
} finally {\r
public void testReadOffice2007(String filename) throws IOException {\r
Workbook wb = _testDataProvider.openSampleWorkbook(filename);\r
Sheet s = wb.getSheet("CF");\r
- ConditionalFormatting cf = null;\r
- ConditionalFormattingRule cr = null;\r
\r
- \r
// Sanity check data\r
assertEquals("Values", s.getRow(0).getCell(0).toString());\r
assertEquals("10.0", s.getRow(2).getCell(0).toString());\r
\r
int fCF = 0, fCF12 = 0, fCFEX = 0;\r
for (int i=0; i<sheetCF.getNumConditionalFormattings(); i++) {\r
- cf = sheetCF.getConditionalFormattingAt(i);\r
+ ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(i);\r
if (cf instanceof HSSFConditionalFormatting) {\r
String str = cf.toString();\r
if (str.contains("[CF]")) fCF++;\r
\r
\r
// Highlight Positive values - Column C\r
- cf = sheetCF.getConditionalFormattingAt(0);\r
+ ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);\r
assertEquals(1, cf.getFormattingRanges().length);\r
assertEquals("C2:C17", cf.getFormattingRanges()[0].formatAsString());\r
\r
assertEquals(1, cf.getNumberOfRules());\r
- cr = cf.getRule(0);\r
+ ConditionalFormattingRule cr = cf.getRule(0);\r
assertEquals(ConditionType.CELL_VALUE_IS, cr.getConditionType());\r
assertEquals(ComparisonOperator.GT, cr.getComparisonOperation());\r
assertEquals("0", cr.getFormula1());\r
ConditionalFormatting readCf = cf.getConditionalFormattingAt(0);\r
readCf.setFormattingRanges(null);\r
}\r
+\r
+\r
+ @SuppressWarnings("deprecation")\r
+ @Test\r
+ public void test52122() throws Exception {\r
+ Workbook workbook = _testDataProvider.createWorkbook();\r
+ Sheet sheet = workbook.createSheet("Conditional Formatting Test");\r
+ sheet.setColumnWidth(0, 256 * 10);\r
+ sheet.setColumnWidth(1, 256 * 10);\r
+ sheet.setColumnWidth(2, 256 * 10);\r
+\r
+ // Create some content.\r
+ // row 0\r
+ Row row = sheet.createRow(0);\r
+\r
+ Cell cell0 = row.createCell(0);\r
+ cell0.setCellType(CellType.NUMERIC);\r
+ cell0.setCellValue(100);\r
+\r
+ Cell cell1 = row.createCell(1);\r
+ cell1.setCellType(CellType.NUMERIC);\r
+ cell1.setCellValue(120);\r
+\r
+ Cell cell2 = row.createCell(2);\r
+ cell2.setCellType(CellType.NUMERIC);\r
+ cell2.setCellValue(130);\r
+\r
+ // row 1\r
+ row = sheet.createRow(1);\r
+\r
+ cell0 = row.createCell(0);\r
+ cell0.setCellType(CellType.NUMERIC);\r
+ cell0.setCellValue(200);\r
+\r
+ cell1 = row.createCell(1);\r
+ cell1.setCellType(CellType.NUMERIC);\r
+ cell1.setCellValue(220);\r
+\r
+ cell2 = row.createCell(2);\r
+ cell2.setCellType(CellType.NUMERIC);\r
+ cell2.setCellValue(230);\r
+\r
+ // row 2\r
+ row = sheet.createRow(2);\r
+\r
+ cell0 = row.createCell(0);\r
+ cell0.setCellType(CellType.NUMERIC);\r
+ cell0.setCellValue(300);\r
+\r
+ cell1 = row.createCell(1);\r
+ cell1.setCellType(CellType.NUMERIC);\r
+ cell1.setCellValue(320);\r
+\r
+ cell2 = row.createCell(2);\r
+ cell2.setCellType(CellType.NUMERIC);\r
+ cell2.setCellValue(330);\r
+\r
+ // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank.\r
+ SheetConditionalFormatting formatting = sheet.getSheetConditionalFormatting();\r
+\r
+ ConditionalFormattingRule rule = formatting.createConditionalFormattingRule("$A$1>75");\r
+\r
+ PatternFormatting pattern = rule.createPatternFormatting();\r
+ pattern.setFillBackgroundColor(IndexedColors.BLUE.index);\r
+ pattern.setFillPattern(PatternFormatting.SOLID_FOREGROUND);\r
+\r
+ CellRangeAddress[] range = {CellRangeAddress.valueOf("B2:C2")};\r
+ CellRangeAddress[] range2 = {CellRangeAddress.valueOf("B1:C1")};\r
+\r
+ formatting.addConditionalFormatting(range, rule);\r
+ formatting.addConditionalFormatting(range2, rule);\r
+\r
+ // Write file.\r
+ /*FileOutputStream fos = new FileOutputStream("c:\\temp\\52122_conditional-sheet.xls");\r
+ try {\r
+ workbook.write(fos);\r
+ } finally {\r
+ fos.close();\r
+ }*/\r
+\r
+ Workbook wbBack = _testDataProvider.writeOutAndReadBack(workbook);\r
+ Sheet sheetBack = wbBack.getSheetAt(0);\r
+ final SheetConditionalFormatting sheetConditionalFormattingBack = sheetBack.getSheetConditionalFormatting();\r
+ assertNotNull(sheetConditionalFormattingBack);\r
+ final ConditionalFormatting formattingBack = sheetConditionalFormattingBack.getConditionalFormattingAt(0);\r
+ assertNotNull(formattingBack);\r
+ final ConditionalFormattingRule ruleBack = formattingBack.getRule(0);\r
+ assertNotNull(ruleBack);\r
+ final PatternFormatting patternFormattingBack1 = ruleBack.getPatternFormatting();\r
+ assertNotNull(patternFormattingBack1);\r
+ assertEquals(IndexedColors.BLUE.index, patternFormattingBack1.getFillBackgroundColor());\r
+ assertEquals(PatternFormatting.SOLID_FOREGROUND, patternFormattingBack1.getFillPattern());\r
+ }\r
}
\ No newline at end of file