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);
}
}
}
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()));
}
}
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());
}
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();
}
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));
}
Aggregations