Search in sources :

Example 1 with SharedValueManager

use of org.apache.poi.hssf.record.aggregates.SharedValueManager 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

ArrayRecord (org.apache.poi.hssf.record.ArrayRecord)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 Record (org.apache.poi.hssf.record.Record)1 RowRecordsAggregate (org.apache.poi.hssf.record.aggregates.RowRecordsAggregate)1 SharedValueManager (org.apache.poi.hssf.record.aggregates.SharedValueManager)1 TestSharedValueManager (org.apache.poi.hssf.record.aggregates.TestSharedValueManager)1 Test (org.junit.Test)1