Search in sources :

Example 1 with ConditionalFormattingTable

use of org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable in project poi by apache.

the class InternalSheet method getConditionalFormattingTable.

public ConditionalFormattingTable getConditionalFormattingTable() {
    if (condFormatting == null) {
        condFormatting = new ConditionalFormattingTable();
        RecordOrderer.addNewSheetRecord(_records, condFormatting);
    }
    return condFormatting;
}
Also used : ConditionalFormattingTable(org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable)

Example 2 with ConditionalFormattingTable

use of org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable in project poi by apache.

the class TestSheet method testShiftFormulasAddCondFormat_bug46547.

/**
	 * 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.
	 */
@Test
public void testShiftFormulasAddCondFormat_bug46547() {
    // Create a sheet with data validity (similar to bugzilla attachment id=23131).
    InternalSheet sheet = InternalSheet.createSheet();
    List<RecordBase> sheetRecs = sheet.getRecords();
    assertEquals(23, sheetRecs.size());
    FormulaShifter shifter = FormulaShifter.createForRowShift(0, "", 0, 0, 1, SpreadsheetVersion.EXCEL97);
    sheet.updateFormulasAfterCellShift(shifter, 0);
    if (sheetRecs.size() == 24 && sheetRecs.get(22) instanceof ConditionalFormattingTable) {
        throw new AssertionFailedError("Identified bug 46547a");
    }
    assertEquals(23, sheetRecs.size());
}
Also used : RecordBase(org.apache.poi.hssf.record.RecordBase) AssertionFailedError(junit.framework.AssertionFailedError) FormulaShifter(org.apache.poi.ss.formula.FormulaShifter) ConditionalFormattingTable(org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable) Test(org.junit.Test)

Example 3 with ConditionalFormattingTable

use of org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable in project poi by apache.

the class TestSheet method testAddCondFormatAfterDataValidation_bug46547.

/**
	 * Bug 46547 happened when attempting to add conditional formatting to a sheet
	 * which already had data validity constraints.
	 */
@Test
public void testAddCondFormatAfterDataValidation_bug46547() {
    // Create a sheet with data validity (similar to bugzilla attachment id=23131).
    InternalSheet sheet = InternalSheet.createSheet();
    sheet.getOrCreateDataValidityTable();
    ConditionalFormattingTable cft;
    // attempt to add conditional formatting
    try {
        // lazy getter
        cft = sheet.getConditionalFormattingTable();
    } catch (ClassCastException e) {
        throw new AssertionFailedError("Identified bug 46547b");
    }
    assertNotNull(cft);
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) ConditionalFormattingTable(org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable) Test(org.junit.Test)

Aggregations

ConditionalFormattingTable (org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable)3 AssertionFailedError (junit.framework.AssertionFailedError)2 Test (org.junit.Test)2 RecordBase (org.apache.poi.hssf.record.RecordBase)1 FormulaShifter (org.apache.poi.ss.formula.FormulaShifter)1