use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class HSSFCell method setCellType.
/**
* sets the cell type. The setValue flag indicates whether to bother about
* trying to preserve the current value in the new record if one is created.
* <p>
* The @see #setCellValue method will call this method with false in setValue
* since it will overwrite the cell value later
*
*/
private void setCellType(CellType cellType, boolean setValue, int row, short col, short styleIndex) {
switch(cellType) {
case FORMULA:
FormulaRecordAggregate frec;
if (cellType != _cellType) {
frec = _sheet.getSheet().getRowsAggregate().createFormula(row, col);
} else {
frec = (FormulaRecordAggregate) _record;
frec.setRow(row);
frec.setColumn(col);
}
if (setValue) {
frec.getFormulaRecord().setValue(getNumericCellValue());
}
frec.setXFIndex(styleIndex);
_record = frec;
break;
case NUMERIC:
NumberRecord nrec = null;
if (cellType != _cellType) {
nrec = new NumberRecord();
} else {
nrec = (NumberRecord) _record;
}
nrec.setColumn(col);
if (setValue) {
nrec.setValue(getNumericCellValue());
}
nrec.setXFIndex(styleIndex);
nrec.setRow(row);
_record = nrec;
break;
case STRING:
LabelSSTRecord lrec;
if (cellType == _cellType) {
lrec = (LabelSSTRecord) _record;
} else {
lrec = new LabelSSTRecord();
lrec.setColumn(col);
lrec.setRow(row);
lrec.setXFIndex(styleIndex);
}
if (setValue) {
String str = convertCellValueToString();
if (str == null) {
// bug 55668: don't try to store null-string when formula
// results in empty/null value
setCellType(CellType.BLANK, false, row, col, styleIndex);
return;
} else {
int sstIndex = _book.getWorkbook().addSSTString(new UnicodeString(str));
lrec.setSSTIndex(sstIndex);
UnicodeString us = _book.getWorkbook().getSSTString(sstIndex);
_stringValue = new HSSFRichTextString();
_stringValue.setUnicodeString(us);
}
}
_record = lrec;
break;
case BLANK:
BlankRecord brec = null;
if (cellType != _cellType) {
brec = new BlankRecord();
} else {
brec = (BlankRecord) _record;
}
brec.setColumn(col);
// During construction the cellStyle may be null for a Blank cell.
brec.setXFIndex(styleIndex);
brec.setRow(row);
_record = brec;
break;
case BOOLEAN:
BoolErrRecord boolRec = null;
if (cellType != _cellType) {
boolRec = new BoolErrRecord();
} else {
boolRec = (BoolErrRecord) _record;
}
boolRec.setColumn(col);
if (setValue) {
boolRec.setValue(convertCellValueToBoolean());
}
boolRec.setXFIndex(styleIndex);
boolRec.setRow(row);
_record = boolRec;
break;
case ERROR:
BoolErrRecord errRec = null;
if (cellType != _cellType) {
errRec = new BoolErrRecord();
} else {
errRec = (BoolErrRecord) _record;
}
errRec.setColumn(col);
if (setValue) {
errRec.setValue(FormulaError.VALUE.getCode());
}
errRec.setXFIndex(styleIndex);
errRec.setRow(row);
_record = errRec;
break;
default:
throw new IllegalStateException("Invalid cell type: " + cellType);
}
if (cellType != _cellType && // Special Value to indicate an uninitialized Cell
_cellType != CellType._NONE) {
_sheet.getSheet().replaceValueRecord(_record);
}
_cellType = cellType;
}
use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class ValueRecordsAggregate method addMultipleBlanks.
public void addMultipleBlanks(MulBlankRecord mbr) {
for (int j = 0; j < mbr.getNumColumns(); j++) {
BlankRecord br = new BlankRecord();
br.setColumn((short) (j + mbr.getFirstColumn()));
br.setRow(mbr.getRow());
br.setXFIndex(mbr.getXFAt(j));
insertCell(br);
}
}
use of org.apache.poi.hssf.record.BlankRecord 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.BlankRecord in project poi by apache.
the class TestValueRecordsAggregate method testGetPhysicalNumberOfCells.
@Test
public void testGetPhysicalNumberOfCells() {
assertEquals(0, valueRecord.getPhysicalNumberOfCells());
BlankRecord blankRecord1 = newBlankRecord();
valueRecord.insertCell(blankRecord1);
assertEquals(1, valueRecord.getPhysicalNumberOfCells());
valueRecord.removeCell(blankRecord1);
assertEquals(0, valueRecord.getPhysicalNumberOfCells());
}
use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class TestValueRecordsAggregate method newBlankRecord.
private static BlankRecord newBlankRecord(int col, int row) {
BlankRecord blankRecord = new BlankRecord();
blankRecord.setRow(row);
blankRecord.setColumn((short) col);
return blankRecord;
}
Aggregations