use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class TestValueRecordsAggregate method testData.
private static List<Record> testData() {
List<Record> records = new ArrayList<Record>();
FormulaRecord formulaRecord = new FormulaRecord();
BlankRecord blankRecord = new BlankRecord();
formulaRecord.setRow(1);
formulaRecord.setColumn((short) 1);
blankRecord.setRow(2);
blankRecord.setColumn((short) 2);
records.add(formulaRecord);
records.add(blankRecord);
records.add(new WindowTwoRecord());
return records;
}
use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class TestValueRecordsAggregate method confirmMulBlank.
private void confirmMulBlank(int expectedTotalBlankCells, int expectedNumberOfMulBlankRecords, int expectedNumberOfSingleBlankRecords) {
// assumed row ranges set-up by caller:
final int firstRow = 1;
final int lastRow = 2;
final class BlankStats {
public int countBlankCells;
public int countMulBlankRecords;
public int countSingleBlankRecords;
}
final BlankStats bs = new BlankStats();
RecordVisitor rv = new RecordVisitor() {
@Override
public void visitRecord(Record r) {
if (r instanceof MulBlankRecord) {
MulBlankRecord mbr = (MulBlankRecord) r;
bs.countMulBlankRecords++;
bs.countBlankCells += mbr.getNumColumns();
} else if (r instanceof BlankRecord) {
bs.countSingleBlankRecords++;
bs.countBlankCells++;
}
}
};
for (int rowIx = firstRow; rowIx <= lastRow; rowIx++) {
if (valueRecord.rowHasCells(rowIx)) {
valueRecord.visitCellsForRow(rowIx, rv);
}
}
assertEquals(expectedTotalBlankCells, bs.countBlankCells);
assertEquals(expectedNumberOfMulBlankRecords, bs.countMulBlankRecords);
assertEquals(expectedNumberOfSingleBlankRecords, bs.countSingleBlankRecords);
}
use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class TestHSSFRow method testLastAndFirstColumns_bug46654.
@Test
public void testLastAndFirstColumns_bug46654() throws IOException {
int ROW_IX = 10;
int COL_IX = 3;
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Sheet1");
RowRecord rowRec = new RowRecord(ROW_IX);
rowRec.setFirstCol((short) 2);
rowRec.setLastCol((short) 5);
BlankRecord br = new BlankRecord();
br.setRow(ROW_IX);
br.setColumn((short) COL_IX);
sheet.getSheet().addValueRecord(ROW_IX, br);
HSSFRow row = new HSSFRow(workbook, sheet, rowRec);
HSSFCell cell = row.createCellFromRecord(br);
if (row.getFirstCellNum() == 2 && row.getLastCellNum() == 5) {
fail("Identified bug 46654a");
}
assertEquals(COL_IX, row.getFirstCellNum());
assertEquals(COL_IX + 1, row.getLastCellNum());
row.removeCell(cell);
assertEquals(-1, row.getFirstCellNum());
assertEquals(-1, row.getLastCellNum());
workbook.close();
}
use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class XLS2CSVmra method processRecord.
/**
* Main HSSFListener method, processes events, and outputs the
* CSV as the file is processed.
*/
@Override
public void processRecord(Record record) {
int thisRow = -1;
int thisColumn = -1;
String thisStr = null;
switch(record.getSid()) {
case BoundSheetRecord.sid:
boundSheetRecords.add((BoundSheetRecord) record);
break;
case BOFRecord.sid:
BOFRecord br = (BOFRecord) record;
if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
// Create sub workbook if required
if (workbookBuildingListener != null && stubWorkbook == null) {
stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
}
// Output the worksheet name
// Works by ordering the BSRs by the location of
// their BOFRecords, and then knowing that we
// process BOFRecords in byte offset order
sheetIndex++;
if (orderedBSRs == null) {
orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords);
}
output.println();
output.println(orderedBSRs[sheetIndex].getSheetname() + " [" + (sheetIndex + 1) + "]:");
}
break;
case SSTRecord.sid:
sstRecord = (SSTRecord) record;
break;
case BlankRecord.sid:
BlankRecord brec = (BlankRecord) record;
thisRow = brec.getRow();
thisColumn = brec.getColumn();
thisStr = "";
break;
case BoolErrRecord.sid:
BoolErrRecord berec = (BoolErrRecord) record;
thisRow = berec.getRow();
thisColumn = berec.getColumn();
thisStr = "";
break;
case FormulaRecord.sid:
FormulaRecord frec = (FormulaRecord) record;
thisRow = frec.getRow();
thisColumn = frec.getColumn();
if (outputFormulaValues) {
if (Double.isNaN(frec.getValue())) {
// Formula result is a string
// This is stored in the next record
outputNextStringRecord = true;
nextRow = frec.getRow();
nextColumn = frec.getColumn();
} else {
thisStr = formatListener.formatNumberDateCell(frec);
}
} else {
thisStr = '"' + HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
}
break;
case StringRecord.sid:
if (outputNextStringRecord) {
// String for formula
StringRecord srec = (StringRecord) record;
thisStr = srec.getString();
thisRow = nextRow;
thisColumn = nextColumn;
outputNextStringRecord = false;
}
break;
case LabelRecord.sid:
LabelRecord lrec = (LabelRecord) record;
thisRow = lrec.getRow();
thisColumn = lrec.getColumn();
thisStr = '"' + lrec.getValue() + '"';
break;
case LabelSSTRecord.sid:
LabelSSTRecord lsrec = (LabelSSTRecord) record;
thisRow = lsrec.getRow();
thisColumn = lsrec.getColumn();
if (sstRecord == null) {
thisStr = '"' + "(No SST Record, can't identify string)" + '"';
} else {
thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
}
break;
case NoteRecord.sid:
NoteRecord nrec = (NoteRecord) record;
thisRow = nrec.getRow();
thisColumn = nrec.getColumn();
// TODO: Find object to match nrec.getShapeId()
thisStr = '"' + "(TODO)" + '"';
break;
case NumberRecord.sid:
NumberRecord numrec = (NumberRecord) record;
thisRow = numrec.getRow();
thisColumn = numrec.getColumn();
// Format
thisStr = formatListener.formatNumberDateCell(numrec);
break;
case RKRecord.sid:
RKRecord rkrec = (RKRecord) record;
thisRow = rkrec.getRow();
thisColumn = rkrec.getColumn();
thisStr = '"' + "(TODO)" + '"';
break;
default:
break;
}
// Handle new row
if (thisRow != -1 && thisRow != lastRowNumber) {
lastColumnNumber = -1;
}
// Handle missing column
if (record instanceof MissingCellDummyRecord) {
MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
thisRow = mc.getRow();
thisColumn = mc.getColumn();
thisStr = "";
}
// If we got something to print out, do so
if (thisStr != null) {
if (thisColumn > 0) {
output.print(',');
}
output.print(thisStr);
}
// Update column and row count
if (thisRow > -1)
lastRowNumber = thisRow;
if (thisColumn > -1)
lastColumnNumber = thisColumn;
// Handle end of row
if (record instanceof LastCellOfRowDummyRecord) {
// Print out any missing commas if needed
if (minColumns > 0) {
// Columns are 0 based
if (lastColumnNumber == -1) {
lastColumnNumber = 0;
}
for (int i = lastColumnNumber; i < (minColumns); i++) {
output.print(',');
}
}
// We're onto a new row
lastColumnNumber = -1;
// End the row
output.println();
}
}
use of org.apache.poi.hssf.record.BlankRecord in project poi by apache.
the class TestMissingRecordAwareHSSFListener method testMulBlankHandling.
/**
* MulBlank records hold multiple blank cells. Check we
* can handle them correctly.
*/
public void testMulBlankHandling() {
readRecords("45672.xls");
// Check that we don't have any MulBlankRecords, but do
// have lots of BlankRecords
Record[] rr = r;
int eorCount = 0;
int mbrCount = 0;
int brCount = 0;
for (Record record : rr) {
if (record instanceof MulBlankRecord) {
mbrCount++;
}
if (record instanceof BlankRecord) {
brCount++;
}
if (record instanceof LastCellOfRowDummyRecord) {
eorCount++;
}
}
if (mbrCount > 0) {
throw new AssertionFailedError("Identified bug 45672");
}
if (brCount < 20) {
throw new AssertionFailedError("Identified bug 45672");
}
if (eorCount != 2) {
throw new AssertionFailedError("Identified bug 45672");
}
assertEquals(2, eorCount);
}
Aggregations