import java.util.Iterator;
import java.util.List;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.BOFRecord;
+import org.apache.poi.hssf.record.CFHeaderRecord;
+import org.apache.poi.hssf.record.CalcCountRecord;
+import org.apache.poi.hssf.record.CalcModeRecord;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.ColumnInfoRecord;
+import org.apache.poi.hssf.record.DVALRecord;
+import org.apache.poi.hssf.record.DefaultColWidthRecord;
+import org.apache.poi.hssf.record.DefaultRowHeightRecord;
+import org.apache.poi.hssf.record.DeltaRecord;
+import org.apache.poi.hssf.record.DimensionsRecord;
+import org.apache.poi.hssf.record.DrawingRecord;
+import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.FeatHdrRecord;
+import org.apache.poi.hssf.record.FeatRecord;
+import org.apache.poi.hssf.record.GridsetRecord;
+import org.apache.poi.hssf.record.GutsRecord;
+import org.apache.poi.hssf.record.IndexRecord;
+import org.apache.poi.hssf.record.IterationRecord;
+import org.apache.poi.hssf.record.MergeCellsRecord;
+import org.apache.poi.hssf.record.NoteRecord;
+import org.apache.poi.hssf.record.PaneRecord;
+import org.apache.poi.hssf.record.PrintGridlinesRecord;
+import org.apache.poi.hssf.record.PrintHeadersRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordBase;
+import org.apache.poi.hssf.record.RecordFormatException;
+import org.apache.poi.hssf.record.RefModeRecord;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.SCLRecord;
+import org.apache.poi.hssf.record.SaveRecalcRecord;
+import org.apache.poi.hssf.record.SelectionRecord;
+import org.apache.poi.hssf.record.UncalcedRecord;
+import org.apache.poi.hssf.record.WSBoolRecord;
+import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.ChartSubstreamRecordAggregate;
import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
if (rs.peekNextSid() != BOFRecord.sid) {
throw new RuntimeException("BOF record expected");
}
+
BOFRecord bof = (BOFRecord) rs.getNext();
- if (bof.getType() != BOFRecord.TYPE_WORKSHEET) {
- // TODO - fix junit tests throw new RuntimeException("Bad BOF record type");
+ if (bof.getType() == BOFRecord.TYPE_WORKSHEET) {
+ // Good, well supported
+ } else if (bof.getType() == BOFRecord.TYPE_CHART ||
+ bof.getType() == BOFRecord.TYPE_EXCEL_4_MACRO) {
+ // These aren't really typical sheets... Let it go though,
+ // we can handle them roughly well enough as a "normal" one
+ } else {
+ // Not a supported type
+ // Skip onto the EOF, then complain
+ while (rs.hasNext()) {
+ Record rec = rs.getNext();
+ if (rec instanceof EOFRecord) {
+ break;
+ }
+ }
+ throw new UnsupportedBOFType(bof.getType());
}
records.add(bof);
+
while (rs.hasNext()) {
int recSid = rs.peekNextSid();
recs.add(r);
}});
}
+
+ public static class UnsupportedBOFType extends RecordFormatException {
+ private final int type;
+ protected UnsupportedBOFType(int type) {
+ super("BOF not of a supported type, found " + type);
+ this.type = type;
+ }
+
+ public int getType() {
+ return type;
+ }
+ }
private static final class RecordCloner implements RecordVisitor {
import org.apache.poi.hssf.record.BoolErrRecord;
import org.apache.poi.hssf.record.CalcCountRecord;
import org.apache.poi.hssf.record.CalcModeRecord;
+import org.apache.poi.hssf.record.ColumnInfoRecord;
import org.apache.poi.hssf.record.DVALRecord;
import org.apache.poi.hssf.record.DateWindow1904Record;
import org.apache.poi.hssf.record.DefaultColWidthRecord;
case DrawingSelectionRecord.sid:
case ObjRecord.sid:
case TextObjectRecord.sid:
-
+ case ColumnInfoRecord.sid: // See Bugzilla 53984
case GutsRecord.sid: // see Bugzilla 50426
case WindowOneRecord.sid:
// should really be part of workbook stream, but some apps seem to put this before WINDOW2
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherClientDataRecord;
* @param loc - location of the record which sid must be returned
* @return sid of the record with selected location
*/
- private static short sid(List <RecordBase>records, int loc) {
- return ((Record) records.get(loc)).getSid();
+ private static short sid(List<RecordBase> records, int loc) {
+ RecordBase record = records.get(loc);
+ if (record instanceof Record) {
+ return ((Record)record).getSid();
+ } else {
+ // Aggregates don't have a sid
+ // We could step into them, but for these needs we don't care
+ return -1;
+ }
}
/**
import org.apache.poi.hssf.model.DrawingManager2;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.InternalSheet;
+import org.apache.poi.hssf.model.InternalSheet.UnsupportedBOFType;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
convertLabelRecords(records, recOffset);
RecordStream rs = new RecordStream(records, recOffset);
while (rs.hasNext()) {
- InternalSheet sheet = InternalSheet.createSheet(rs);
- _sheets.add(new HSSFSheet(this, sheet));
+ try {
+ InternalSheet sheet = InternalSheet.createSheet(rs);
+ _sheets.add(new HSSFSheet(this, sheet));
+ } catch (UnsupportedBOFType eb) {
+ // Hopefully there's a supported one after this!
+ log.log(POILogger.WARN, "Unsupported BOF found of type " + eb.getType());
+ }
}
for (int i = 0 ; i < workbook.getNumNames() ; ++i){