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
This commit is contained in:
parent
fda28eae8b
commit
705c3fe1f9
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.hssf.model.RecordStream;
|
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.hssf.record.CFHeaderRecord;
|
||||||
import org.apache.poi.ss.formula.FormulaShifter;
|
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.<p/>
|
* Holds all the conditional formatting for a workbook sheet.<p/>
|
||||||
*
|
*
|
||||||
* See OOO exelfileformat.pdf sec 4.12 'Conditional Formatting Table'
|
* See OOO exelfileformat.pdf sec 4.12 'Conditional Formatting Table'
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
*/
|
*/
|
||||||
public final class ConditionalFormattingTable extends RecordAggregate {
|
public final class ConditionalFormattingTable extends RecordAggregate {
|
||||||
|
|
||||||
private final List<CFRecordsAggregate> _cfHeaders;
|
private final List<CFRecordsAggregate> _cfHeaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +43,8 @@ public final class ConditionalFormattingTable extends RecordAggregate {
|
|||||||
public ConditionalFormattingTable(RecordStream rs) {
|
public ConditionalFormattingTable(RecordStream rs) {
|
||||||
|
|
||||||
List<CFRecordsAggregate> temp = new ArrayList<CFRecordsAggregate>();
|
List<CFRecordsAggregate> temp = new ArrayList<CFRecordsAggregate>();
|
||||||
while (rs.peekNextClass() == CFHeaderRecord.class) {
|
while (rs.peekNextClass() == CFHeaderRecord.class ||
|
||||||
|
rs.peekNextClass() == CFHeader12Record.class) {
|
||||||
temp.add(CFRecordsAggregate.createCFAggregate(rs));
|
temp.add(CFRecordsAggregate.createCFAggregate(rs));
|
||||||
}
|
}
|
||||||
_cfHeaders = temp;
|
_cfHeaders = temp;
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFConditionalFormatting;
|
||||||
import org.apache.poi.ss.ITestDataProvider;
|
import org.apache.poi.ss.ITestDataProvider;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
|
||||||
@ -528,6 +530,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
|
|||||||
Workbook wb = _testDataProvider.openSampleWorkbook(filename);
|
Workbook wb = _testDataProvider.openSampleWorkbook(filename);
|
||||||
Sheet s = wb.getSheet("CF");
|
Sheet s = wb.getSheet("CF");
|
||||||
ConditionalFormatting cf = null;
|
ConditionalFormatting cf = null;
|
||||||
|
ConditionalFormattingRule cr = null;
|
||||||
|
|
||||||
// Sanity check data
|
// Sanity check data
|
||||||
assertEquals("Values", s.getRow(0).getCell(0).toString());
|
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
|
// Check we found all the conditional formattings rules we should have
|
||||||
SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting();
|
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);
|
int fCF = 0, fCF12 = 0, fCFEX = 0;
|
||||||
//System.out.println(cf);
|
for (int i=0; i<sheetCF.getNumConditionalFormattings(); i++) {
|
||||||
|
cf = sheetCF.getConditionalFormattingAt(i);
|
||||||
|
if (cf instanceof HSSFConditionalFormatting) {
|
||||||
|
String str = cf.toString();
|
||||||
|
if (str.contains("[CF]")) fCF++;
|
||||||
|
if (str.contains("[CF12]")) fCF12++;
|
||||||
|
if (str.contains("[CFEX]")) fCFEX++;
|
||||||
|
} else {
|
||||||
|
fail("TODO!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(numCF, fCF);
|
||||||
|
assertEquals(numCF12, fCF12);
|
||||||
|
assertEquals(numCFEX, fCFEX);
|
||||||
|
|
||||||
|
|
||||||
// Check the rules / values in detail
|
// Check the rules / values in detail
|
||||||
|
|
||||||
// Highlight Positive values - Column C
|
// Highlight Positive values - Column C
|
||||||
// TODO
|
cf = sheetCF.getConditionalFormattingAt(0);
|
||||||
|
assertEquals(1, cf.getFormattingRanges().length);
|
||||||
|
assertEquals("C2:C17", cf.getFormattingRanges()[0].formatAsString());
|
||||||
|
|
||||||
|
assertEquals(1, cf.getNumberOfRules());
|
||||||
|
cr = cf.getRule(0);
|
||||||
|
// TODO Check the rest of this
|
||||||
|
|
||||||
// Highlight 10-30 - Column D
|
// Highlight 10-30 - Column D
|
||||||
// TODO
|
// TODO
|
||||||
|
Loading…
Reference in New Issue
Block a user