aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/hssf/usermodel
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2006-11-30 16:15:55 +0000
committerNick Burch <nick@apache.org>2006-11-30 16:15:55 +0000
commitda9b705c5df569ac4d71be1aa8997d025cc3fdca (patch)
tree120d0684d5426899d152e70aedd5e36ab7630df2 /src/java/org/apache/poi/hssf/usermodel
parent925f724d4cc4f604694c7f7ac9ac78a7792ba7f6 (diff)
downloadpoi-da9b705c5df569ac4d71be1aa8997d025cc3fdca.tar.gz
poi-da9b705c5df569ac4d71be1aa8997d025cc3fdca.zip
Support Excel files which contain a WORKBOOK entry, rather than the usual Workbook one. Fixes bug 40840
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@480987 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf/usermodel')
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index 13c4669e22..14d0821dd8 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -38,6 +38,7 @@ import org.apache.poi.util.POILogFactory;
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;
@@ -175,8 +176,29 @@ public class HSSFWorkbook
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();