Search in sources :

Example 1 with CellValueRecordInterface

use of org.apache.poi.hssf.record.CellValueRecordInterface in project poi by apache.

the class ValueRecordsAggregate method visitCellsForRow.

public void visitCellsForRow(int rowIndex, RecordVisitor rv) {
    CellValueRecordInterface[] rowCells = records[rowIndex];
    if (rowCells == null) {
        throw new IllegalArgumentException("Row [" + rowIndex + "] is empty");
    }
    for (int i = 0; i < rowCells.length; i++) {
        RecordBase cvr = (RecordBase) rowCells[i];
        if (cvr == null) {
            continue;
        }
        int nBlank = countBlanks(rowCells, i);
        if (nBlank > 1) {
            rv.visitRecord(createMBR(rowCells, i, nBlank));
            i += nBlank - 1;
        } else if (cvr instanceof RecordAggregate) {
            RecordAggregate agg = (RecordAggregate) cvr;
            agg.visitContainedRecords(rv);
        } else {
            rv.visitRecord((Record) cvr);
        }
    }
}
Also used : CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) RecordBase(org.apache.poi.hssf.record.RecordBase) Record(org.apache.poi.hssf.record.Record) StringRecord(org.apache.poi.hssf.record.StringRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord)

Example 2 with CellValueRecordInterface

use of org.apache.poi.hssf.record.CellValueRecordInterface in project poi by apache.

the class HSSFRow method removeCell.

private void removeCell(HSSFCell cell, boolean alsoRemoveRecords) {
    int column = cell.getColumnIndex();
    if (column < 0) {
        throw new RuntimeException("Negative cell indexes not allowed");
    }
    if (column >= cells.length || cell != cells[column]) {
        throw new RuntimeException("Specified cell is not from this row");
    }
    if (cell.isPartOfArrayFormulaGroup()) {
        cell.notifyArrayFormulaChanging();
    }
    cells[column] = null;
    if (alsoRemoveRecords) {
        CellValueRecordInterface cval = cell.getCellValueRecord();
        sheet.getSheet().removeValueRecord(getRowNum(), cval);
    }
    if (cell.getColumnIndex() + 1 == row.getLastCol()) {
        row.setLastCol(calculateNewLastCellPlusOne(row.getLastCol()));
    }
    if (cell.getColumnIndex() == row.getFirstCol()) {
        row.setFirstCol(calculateNewFirstCell(row.getFirstCol()));
    }
}
Also used : CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface)

Example 3 with CellValueRecordInterface

use of org.apache.poi.hssf.record.CellValueRecordInterface in project poi by apache.

the class TestSheet method testSheetDimensions.

@Test
public void testSheetDimensions() throws IOException {
    InternalSheet sheet = InternalSheet.createSheet();
    DimensionsRecord dimensions = (DimensionsRecord) sheet.findFirstRecordBySid(DimensionsRecord.sid);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    // plus pne
    assertEquals(1, dimensions.getLastCol());
    // plus pne
    assertEquals(1, dimensions.getLastRow());
    RowRecord rr = new RowRecord(0);
    sheet.addRow(rr);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    assertEquals(1, dimensions.getLastCol());
    assertEquals(1, dimensions.getLastRow());
    CellValueRecordInterface cvr;
    cvr = new BlankRecord();
    cvr.setColumn((short) 0);
    cvr.setRow(0);
    sheet.addValueRecord(0, cvr);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    assertEquals(1, dimensions.getLastCol());
    assertEquals(1, dimensions.getLastRow());
    cvr = new BlankRecord();
    cvr.setColumn((short) 1);
    cvr.setRow(0);
    sheet.addValueRecord(0, cvr);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    //YK:  failed until Bugzilla 53414 was fixed
    assertEquals(2, dimensions.getLastCol());
    assertEquals(1, dimensions.getLastRow());
}
Also used : MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) RowRecord(org.apache.poi.hssf.record.RowRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) Test(org.junit.Test)

Example 4 with CellValueRecordInterface

use of org.apache.poi.hssf.record.CellValueRecordInterface in project poi by apache.

the class FormulaExtractor method getPtgs.

public static Ptg[] getPtgs(HSSFCell cell) {
    CellValueRecordInterface vr = cell.getCellValueRecord();
    if (!(vr instanceof FormulaRecordAggregate)) {
        throw new IllegalArgumentException("Not a formula cell");
    }
    FormulaRecordAggregate fra = (FormulaRecordAggregate) vr;
    return fra.getFormulaRecord().getParsedExpression();
}
Also used : CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) FormulaRecordAggregate(org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate)

Example 5 with CellValueRecordInterface

use of org.apache.poi.hssf.record.CellValueRecordInterface in project poi by apache.

the class TestValueRecordsAggregate method testSharedFormula.

/**
	 * Make sure the shared formula DOESNT makes it to the FormulaRecordAggregate when being parsed
	 * as part of the value records
	 */
@Test
public void testSharedFormula() {
    List<Record> records = new ArrayList<Record>();
    records.add(new FormulaRecord());
    records.add(new SharedFormulaRecord());
    records.add(new WindowTwoRecord());
    constructValueRecord(records);
    List<CellValueRecordInterface> cvrs = getValueRecords();
    //Ensure that the SharedFormulaRecord has been converted
    assertEquals(1, cvrs.size());
    CellValueRecordInterface record = cvrs.get(0);
    assertNotNull("Row contains a value", record);
    assertTrue("First record is a FormulaRecordsAggregate", (record instanceof FormulaRecordAggregate));
}
Also used : SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) ArrayList(java.util.ArrayList) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) Record(org.apache.poi.hssf.record.Record) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) Test(org.junit.Test)

Aggregations

CellValueRecordInterface (org.apache.poi.hssf.record.CellValueRecordInterface)14 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)6 BlankRecord (org.apache.poi.hssf.record.BlankRecord)5 Test (org.junit.Test)5 Record (org.apache.poi.hssf.record.Record)4 RowRecord (org.apache.poi.hssf.record.RowRecord)4 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)3 FormulaRecordAggregate (org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate)3 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)2 StringRecord (org.apache.poi.hssf.record.StringRecord)2 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)2 Cell (org.apache.poi.ss.usermodel.Cell)2 ArrayList (java.util.ArrayList)1 AssertionFailedError (junit.framework.AssertionFailedError)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 LastCellOfRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord)1 MissingCellDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)1 MissingRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord)1 InternalSheet (org.apache.poi.hssf.model.InternalSheet)1 AutoFilterInfoRecord (org.apache.poi.hssf.record.AutoFilterInfoRecord)1