import org.apache.poi.util.POILogger;
import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
sheets = new ArrayList(INITIAL_CAPACITY);
names = new ArrayList(INITIAL_CAPACITY);
+
+ // Normally, the Workbook will be in a POIFS Stream
+ // called "Workbook". However, some wierd XLS generators
+ // put theirs in one called "WORKBOOK"
+ String workbookName = "Workbook";
+ try {
+ fs.getRoot().getEntry(workbookName);
+ // Is the default name
+ } catch(FileNotFoundException fe) {
+ // Try the upper case form
+ try {
+ workbookName = "WORKBOOK";
+ fs.getRoot().getEntry(workbookName);
+ } catch(FileNotFoundException wfe) {
+ // Doesn't contain it in either form
+ throw new IllegalArgumentException("The supplied POIFSFileSystem contained neither a 'Workbook' entry, nor a 'WORKBOOK' entry. Is it really an excel file?");
+ }
+ }
- InputStream stream = fs.createDocumentInputStream("Workbook");
+
+ // Grab the data from the workbook stream, however
+ // it happens to be spelt.
+ InputStream stream = fs.createDocumentInputStream(workbookName);
EventRecordFactory factory = new EventRecordFactory();
--- /dev/null
+package org.apache.poi.hssf.usermodel;
+
+import java.io.FileInputStream;
+
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for how HSSFWorkbook behaves with XLS files
+ * with a WORKBOOK directory entry (instead of the more
+ * usual, Workbook)
+ */
+public class TestUppercaseWorkbook extends TestCase {
+ private String dirPath;
+ private String xlsA = "WORKBOOK_in_capitals.xls";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ dirPath = System.getProperty("HSSF.testdata.path");
+ }
+
+ /**
+ * Test that we can open a file with WORKBOOK
+ */
+ public void testOpen() throws Exception {
+ FileInputStream is = new FileInputStream(dirPath + "/" + xlsA);
+
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+
+ // Ensure that we have a WORKBOOK entry
+ fs.getRoot().getEntry("WORKBOOK");
+ assertTrue(true);
+
+ // Try to open the workbook
+ HSSFWorkbook wb = new HSSFWorkbook(fs);
+ }
+}