From 0ae3cb9de04d634e629a134061cfaf527489f324 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 13 Jul 2015 18:55:42 +0000 Subject: [PATCH] Have the HSSF ConditionalFormattingTable look for CF12 records as well, and begin more detailed testing of the high level rules #58130 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1690796 13f79535-47bb-0310-9956-ffa450edef68 --- .../ConditionalFormattingTable.java | 7 ++-- .../BaseTestConditionalFormatting.java | 33 ++++++++++++++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java b/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java index 33a2f7b294..e5ea515e80 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.poi.hssf.model.RecordStream; +import org.apache.poi.hssf.record.CFHeader12Record; import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.ss.formula.FormulaShifter; @@ -28,11 +29,8 @@ import org.apache.poi.ss.formula.FormulaShifter; * Holds all the conditional formatting for a workbook sheet.

* * See OOO exelfileformat.pdf sec 4.12 'Conditional Formatting Table' - * - * @author Josh Micich */ public final class ConditionalFormattingTable extends RecordAggregate { - private final List _cfHeaders; /** @@ -45,7 +43,8 @@ public final class ConditionalFormattingTable extends RecordAggregate { public ConditionalFormattingTable(RecordStream rs) { List temp = new ArrayList(); - while (rs.peekNextClass() == CFHeaderRecord.class) { + while (rs.peekNextClass() == CFHeaderRecord.class || + rs.peekNextClass() == CFHeader12Record.class) { temp.add(CFRecordsAggregate.createCFAggregate(rs)); } _cfHeaders = temp; diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java index 1fb7ada606..cb7f19aa8f 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java @@ -20,6 +20,8 @@ package org.apache.poi.ss.usermodel; import junit.framework.TestCase; + +import org.apache.poi.hssf.usermodel.HSSFConditionalFormatting; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.util.CellRangeAddress; @@ -528,6 +530,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase { Workbook wb = _testDataProvider.openSampleWorkbook(filename); Sheet s = wb.getSheet("CF"); ConditionalFormatting cf = null; + ConditionalFormattingRule cr = null; // Sanity check data assertEquals("Values", s.getRow(0).getCell(0).toString()); @@ -535,16 +538,38 @@ public abstract class BaseTestConditionalFormatting extends TestCase { // Check we found all the conditional formattings rules we should have SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting(); - assertEquals(1, sheetCF.getNumConditionalFormattings()); // TODO Should be more! + int numCF = 3; + int numCF12 = 15; + int numCFEX = 0; // TODO This should be 1, but we don't support CFEX formattings yet + assertEquals(numCF+numCF12+numCFEX, sheetCF.getNumConditionalFormattings()); - cf = sheetCF.getConditionalFormattingAt(0); - //System.out.println(cf); + int fCF = 0, fCF12 = 0, fCFEX = 0; + for (int i=0; i