package org.apache.poi.hssf.extractor;
+import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
+
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
private void open(DirectoryNode directory) throws IOException {
DocumentNode book;
try {
- book = (DocumentNode)directory.getEntry("Book");
+ book = (DocumentNode)directory.getEntry(OLD_WORKBOOK_DIR_ENTRY_NAME);
} catch (FileNotFoundException e) {
// some files have "Workbook" instead
- book = (DocumentNode)directory.getEntry("Workbook");
+ book = (DocumentNode)directory.getEntry(WORKBOOK_DIR_ENTRY_NAMES[0]);
}
if (book == null) {
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.ddf.EscherSplitMenuColorsRecord;
+import org.apache.poi.hssf.extractor.OldExcelExtractor;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.BookBoolRecord;
"WORKBOOK", // Typically from third party programs
"BOOK", // Typically odd Crystal Reports exports
};
+ /**
+ * Name of older (pre-Excel 97) Workbook streams, which
+ * aren't supported by HSSFWorkbook, only by
+ * {@link OldExcelExtractor}
+ */
+ public static final String OLD_WORKBOOK_DIR_ENTRY_NAME = "Book";
private static final POILogger log = POILogFactory.getLogger(InternalWorkbook.class);
private static final int DEBUG = POILogger.DEBUG;
package org.apache.poi.hssf.usermodel;
import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
// check for previous version of file format
try {
- directory.getEntry("Book");
+ directory.getEntry(OLD_WORKBOOK_DIR_ENTRY_NAME);
throw new OldExcelFormatException("The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. "
+ "POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)");
} catch (FileNotFoundException e) {
==================================================================== */
package org.apache.poi.extractor;
+import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
+import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
+import org.apache.poi.hssf.extractor.OldExcelExtractor;
import org.apache.poi.hwpf.OldWordFileFormatException;
import org.apache.poi.hwpf.extractor.Word6Extractor;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.xmlbeans.XmlException;
-import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
-
/**
* Figures out the correct POITextExtractor for your supplied
* document, and returns it.
return new ExcelExtractor(poifsDir);
}
}
+ if (poifsDir.hasEntry(OLD_WORKBOOK_DIR_ENTRY_NAME)) {
+ throw new IllegalArgumentException("Excel 1-95 file found, call OldExcelExtractor directly");
+ }
if (poifsDir.hasEntry("WordDocument")) {
// Old or new style word document?