Fix for bug 46547 - Allow for addition of conditional formatting when data validations are present. Avoid creation of and empty conditional formatting table while shifting formulas.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@736175 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-01-21 00:19:49 +00:00
parent 73a498fb35
commit 07fd83a278
5 changed files with 632 additions and 576 deletions

View File

@ -37,7 +37,8 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta5" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="fix">46548 - Print Settings Block fixes - continued PLS records and PSB in sheet sub-streams</action>
<action dev="POI-DEVELOPERS" type="fix">46547 - Allow addition of conditional formatting after data validation</action>
<action dev="POI-DEVELOPERS" type="fix">46548 - Page Settings Block fixes - continued PLS records and PSB in sheet sub-streams</action>
<action dev="POI-DEVELOPERS" type="add">46523 - added implementation for SUMIF function</action>
<action dev="POI-DEVELOPERS" type="add">Support for reading HSSF column styles</action>
<action dev="POI-DEVELOPERS" type="fix">Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor</action>

View File

@ -34,7 +34,8 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta5" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="fix">46548 - Print Settings Block fixes - continued PLS records and PSB in sheet sub-streams</action>
<action dev="POI-DEVELOPERS" type="fix">46547 - Allow addition of conditional formatting after data validation</action>
<action dev="POI-DEVELOPERS" type="fix">46548 - Page Settings Block fixes - continued PLS records and PSB in sheet sub-streams</action>
<action dev="POI-DEVELOPERS" type="add">46523 - added implementation for SUMIF function</action>
<action dev="POI-DEVELOPERS" type="add">Support for reading HSSF column styles</action>
<action dev="POI-DEVELOPERS" type="fix">Hook up POIXMLTextExtractor.getMetadataTextExtractor() to the already written POIXMLPropertiesTextExtractor</action>

View File

@ -91,7 +91,7 @@ final class RecordOrderer {
sheetRecords.add(index, newRecord);
}
private static int findSheetInsertPos(List<RecordBase> records, Class recClass) {
private static int findSheetInsertPos(List<RecordBase> records, Class<? extends RecordBase> recClass) {
if (recClass == DataValidityTable.class) {
return findDataValidationTableInsertPos(records);
}
@ -160,6 +160,10 @@ final class RecordOrderer {
if (rb instanceof MergedCellsTable) {
return i + 1;
}
if (rb instanceof DataValidityTable) {
continue;
}
Record rec = (Record) rb;
switch (rec.getSid()) {
case WindowTwoRecord.sid:
@ -170,7 +174,10 @@ final class RecordOrderer {
// MergedCellsTable usually here
case UnknownRecord.LABELRANGES_015F:
case UnknownRecord.PHONETICPR_00EF:
// ConditionalFormattingTable goes here
return i + 1;
// HyperlinkTable (not aggregated by POI yet)
// DataValidityTable
}
}
throw new RuntimeException("Did not find Window2 record");

View File

@ -504,7 +504,9 @@ public final class Sheet implements Model {
*/
public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) {
getRowsAggregate().updateFormulasAfterRowShift(shifter, externSheetIndex);
if (condFormatting != null) {
getConditionalFormattingTable().updateFormulasAfterCellShift(shifter, externSheetIndex);
}
// TODO - adjust data validations
}

View File

@ -36,12 +36,15 @@ import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.hssf.record.UncalcedRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.record.formula.FormulaShifter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
@ -50,12 +53,12 @@ import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
import org.apache.poi.ss.util.CellRangeAddress;
/**
* Unit test for the Sheet class.
* Unit test for the {@link Sheet} class.
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public final class TestSheet extends TestCase {
private static Sheet createSheet(List inRecs) {
private static Sheet createSheet(List<Record> inRecs) {
return Sheet.createSheet(new RecordStream(inRecs, 0));
}
@ -544,7 +547,7 @@ public final class TestSheet extends TestCase {
sheet.addRow(new RowRecord(1));
sheet.groupRowRange( 0, 1, true );
sheet.toString();
List recs = sheet.getRecords();
List<RecordBase> recs = sheet.getRecords();
int count=0;
for(int i=0; i< recs.size(); i++) {
if (recs.get(i) instanceof GutsRecord) {
@ -626,4 +629,46 @@ public final class TestSheet extends TestCase {
assertEquals(colIx, dims.getFirstCol());
assertEquals(colIx, dims.getLastCol());
}
/**
* Prior to the fix for bug 46547, shifting formulas would have the side-effect
* of creating a {@link ConditionalFormattingTable}. There was no impairment to
* functionality since empty record aggregates are equivalent to missing record
* aggregates. However, since this unnecessary creation helped expose bug 46547b,
* and since there is a slight performance hit the fix was made to avoid it.
*/
public void testShiftFormulasAddCondFormat_bug46547() {
// Create a sheet with data validity (similar to bugzilla attachment id=23131).
Sheet sheet = Sheet.createSheet();
List<RecordBase> sheetRecs = sheet.getRecords();
assertEquals(22, sheetRecs.size());
FormulaShifter shifter = FormulaShifter.createForRowShift(0, 0, 0, 1);
sheet.updateFormulasAfterCellShift(shifter, 0);
if (sheetRecs.size() == 23 && sheetRecs.get(21) instanceof ConditionalFormattingTable) {
throw new AssertionFailedError("Identified bug 46547a");
}
assertEquals(22, sheetRecs.size());
}
/**
* Bug 46547 happened when attempting to add conditional formatting to a sheet
* which already had data validity constraints.
*/
public void testAddCondFormatAfterDataValidation_bug46547() {
// Create a sheet with data validity (similar to bugzilla attachment id=23131).
Sheet sheet = Sheet.createSheet();
sheet.getOrCreateDataValidityTable();
ConditionalFormattingTable cft;
// attempt to add conditional formatting
try {
cft = sheet.getConditionalFormattingTable(); // lazy getter
} catch (ClassCastException e) {
throw new AssertionFailedError("Identified bug 46547b");
}
assertNotNull(cft);
}
}