Hello all,
has anybody time to check this?
I have trouble to extract a tabled embedded into a word document.
I followed to online guides as much as possible in the following manner:
---
...
String fileName = args[0];
InputStream inputStream = new FileInputStream(fileName);
fs = new POIFSFileSystem(inputStream);
DirectoryEntry root = fs.getRoot();
recurse(root, 0);
}
private static void recurse(DirectoryEntry root, int level) throws
Exception {
for (Iterator iter = root.getEntries(); iter.hasNext();) {
Entry entry = (Entry) iter.next();
for (int i = 0; i < level; i++)
System.out.print(" ");
if (entry instanceof DirectoryEntry) {
System.out.println("found directory entry: " +
entry.getName());
try {
HSSFWorkbook wb = new HSSFWorkbook((DirectoryNode) entry,
fs, false);
System.out.println(" found Excel object with " +
wb.getNumberOfSheets() + " sheets");
}
catch (Exception e) {
e.printStackTrace();
}
recurse((DirectoryEntry) entry, ++level);
level--;
}
}
}
At runtime I have valid "fs" and DirectoryEntry "entry" but I get
found directory entry: ObjectPool
found directory entry: _1147433807
java.lang.IllegalArgumentException: The supplied POIFSFileSystem contained
neither a 'Workbook' entry, nor a 'WORKBOOK' entry. Is it really an excel
file?
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:215)
Looking at the source of HSSFWorkbook.java I see that the entry is supposed
to be name /^workbook$/i
Reading the POIFS docu though hints that embedded documents may start with
underscore followed by numbers as is the case with my test case.
What is wrong with my code?
Thanks for any help,
Axel.
Using POI-3.1-beta2