import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
import org.apache.poi.hssf.record.BOFRecord;
+import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.MulBlankRecord;
+import org.apache.poi.hssf.record.MulRKRecord;
import org.apache.poi.hssf.record.NoteRecord;
+import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.SharedFormulaRecord;
public void processRecord(Record record) {
int thisRow;
int thisColumn;
-
+ CellValueRecordInterface[] expandedRecords = null;
if (record instanceof CellValueRecordInterface) {
CellValueRecordInterface valueRec = (CellValueRecordInterface) record;
// - so don't fire off the LastCellOfRowDummyRecord yet
childListener.processRecord(record);
return;
+ case MulBlankRecord.sid:
+ // These appear in the middle of the cell records, to
+ // specify that the next bunch are empty but styled
+ // Expand this out into multiple blank cells
+ MulBlankRecord mbr = (MulBlankRecord)record;
+ expandedRecords = RecordFactory.convertBlankRecords(mbr);
+ break;
+ case MulRKRecord.sid:
+ // This is multiple consecutive number cells in one record
+ // Exand this out into multiple regular number cells
+ MulRKRecord mrk = (MulRKRecord)record;
+ expandedRecords = RecordFactory.convertRKRecords(mrk);
+ break;
case NoteRecord.sid:
NoteRecord nrec = (NoteRecord) record;
thisRow = nrec.getRow();
break;
}
}
+
+ // First part of expanded record handling
+ if(expandedRecords != null && expandedRecords.length > 0) {
+ thisRow = expandedRecords[0].getRow();
+ thisColumn = expandedRecords[0].getColumn();
+ }
+
// If we're on cells, and this cell isn't in the same
// row as the last one, then fire the
// dummy end-of-row records
}
}
+ // Next part of expanded record handling
+ if(expandedRecords != null && expandedRecords.length > 0) {
+ thisColumn = expandedRecords[expandedRecords.length-1].getColumn();
+ }
+
+
// Update cell and row counts as needed
if(thisColumn != -1) {
lastCellColumn = thisColumn;
lastCellRow = thisRow;
}
- childListener.processRecord(record);
+ // Pass along the record(s)
+ if(expandedRecords != null && expandedRecords.length > 0) {
+ for(CellValueRecordInterface r : expandedRecords) {
+ childListener.processRecord((Record)r);
+ }
+ } else {
+ childListener.processRecord(record);
+ }
}
private void resetCounts() {
* Converts a {@link MulRKRecord} into an equivalent array of {@link NumberRecord}s
*/
public static NumberRecord[] convertRKRecords(MulRKRecord mrk) {
-
NumberRecord[] mulRecs = new NumberRecord[mrk.getNumColumns()];
for (int k = 0; k < mrk.getNumColumns(); k++) {
NumberRecord nr = new NumberRecord();
return mulRecs;
}
+ /**
+ * Converts a {@link MulBlankRecord} into an equivalent array of {@link BlankRecord}s
+ */
+ public static BlankRecord[] convertBlankRecords(MulBlankRecord mbk) {
+ BlankRecord[] mulRecs = new BlankRecord[mbk.getNumColumns()];
+ for (int k = 0; k < mbk.getNumColumns(); k++) {
+ BlankRecord br = new BlankRecord();
+
+ br.setColumn((short) (k + mbk.getFirstColumn()));
+ br.setRow(mbk.getRow());
+ br.setXFIndex(mbk.getXFAt(k));
+ mulRecs[k] = br;
+ }
+ return mulRecs;
+ }
+
/**
* @return an array of all the SIDS for all known records
*/
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
import org.apache.poi.hssf.record.BOFRecord;
+import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
+import org.apache.poi.hssf.record.MulBlankRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.SharedFormulaRecord;
assertEquals(1, eorCount);
assertEquals(1, sfrCount);
}
+
+ /**
+ * 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 (int i = 0; i < rr.length; i++) {
+ Record record = rr[i];
+ 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);
+ }
}