Search in sources :

Example 6 with RowRecordsAggregate

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

the class TestHSSFSheetUpdateArrayFormulas method testAddRemoveArrayFormulas_recordUpdates.

/**
     * Makes sure the internal state of HSSFSheet is consistent after removing array formulas
     */
@Test
public void testAddRemoveArrayFormulas_recordUpdates() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet s = wb.createSheet("Sheet1");
    CellRange<HSSFCell> cr = s.setArrayFormula("123", CellRangeAddress.valueOf("B5:C6"));
    Record[] recs;
    int ix;
    recs = RecordInspector.getRecords(s, 0);
    ix = findRecordOfType(recs, ArrayRecord.class, 0);
    confirmRecordClass(recs, ix - 1, FormulaRecord.class);
    confirmRecordClass(recs, ix + 1, FormulaRecord.class);
    confirmRecordClass(recs, ix + 2, FormulaRecord.class);
    confirmRecordClass(recs, ix + 3, FormulaRecord.class);
    // just one array record
    assertTrue(findRecordOfType(recs, ArrayRecord.class, ix + 1) < 0);
    s.removeArrayFormula(cr.getTopLeftCell());
    // Make sure the array formula has been removed properly
    recs = RecordInspector.getRecords(s, 0);
    assertTrue(findRecordOfType(recs, ArrayRecord.class, 0) < 0);
    assertTrue(findRecordOfType(recs, FormulaRecord.class, 0) < 0);
    RowRecordsAggregate rra = s.getSheet().getRowsAggregate();
    SharedValueManager svm = TestSharedValueManager.extractFromRRA(rra);
    if (svm.getArrayRecord(4, 1) != null) {
        fail("Array record was not cleaned up properly.");
    }
    wb.close();
}
Also used : ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) TestSharedValueManager(org.apache.poi.hssf.record.aggregates.TestSharedValueManager) SharedValueManager(org.apache.poi.hssf.record.aggregates.SharedValueManager) Record(org.apache.poi.hssf.record.Record) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) RowRecordsAggregate(org.apache.poi.hssf.record.aggregates.RowRecordsAggregate) Test(org.junit.Test)

Aggregations

RowRecordsAggregate (org.apache.poi.hssf.record.aggregates.RowRecordsAggregate)6 Record (org.apache.poi.hssf.record.Record)5 RecordBase (org.apache.poi.hssf.record.RecordBase)5 Test (org.junit.Test)5 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)4 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)4 EscherRecord (org.apache.poi.ddf.EscherRecord)4 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)4 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)4 EOFRecord (org.apache.poi.hssf.record.EOFRecord)4 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)4 NoteRecord (org.apache.poi.hssf.record.NoteRecord)4 ObjRecord (org.apache.poi.hssf.record.ObjRecord)4 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)4 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)4 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)4 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)4 ArrayRecord (org.apache.poi.hssf.record.ArrayRecord)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 SharedValueManager (org.apache.poi.hssf.record.aggregates.SharedValueManager)1