--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.hssf.usermodel.examples;\r
+\r
+import java.io.FileInputStream;\r
+import java.util.Iterator;\r
+\r
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;\r
+import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;\r
+import org.apache.poi.hssf.usermodel.HSSFObjectData;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.hwpf.HWPFDocument;\r
+import org.apache.poi.poifs.filesystem.DirectoryNode;\r
+import org.apache.poi.poifs.filesystem.Entry;\r
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;\r
+\r
+/**\r
+ * Demonstrates how you can extract embedded data from a .xls file\r
+ */\r
+public class EmbeddedObjects {\r
+ @SuppressWarnings("unused")\r
+ public static void main(String[] args) throws Exception {\r
+ POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));\r
+ HSSFWorkbook workbook = new HSSFWorkbook(fs);\r
+ for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {\r
+ //the OLE2 Class Name of the object\r
+ String oleName = obj.getOLE2ClassName();\r
+ if (oleName.equals("Worksheet")) {\r
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
+ HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false);\r
+ //System.out.println(entry.getName() + ": " + embeddedWorkbook.getNumberOfSheets());\r
+ embeddedWorkbook.close();\r
+ } else if (oleName.equals("Document")) {\r
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
+ HWPFDocument embeddedWordDocument = new HWPFDocument(dn);\r
+ //System.out.println(entry.getName() + ": " + embeddedWordDocument.getRange().text());\r
+ } else if (oleName.equals("Presentation")) {\r
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
+ HSLFSlideShow embeddedPowerPointDocument = new HSLFSlideShow(new HSLFSlideShowImpl(dn));\r
+ //System.out.println(entry.getName() + ": " + embeddedPowerPointDocument.getSlides().length);\r
+ } else {\r
+ if(obj.hasDirectoryEntry()){\r
+ // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is\r
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
+ for (Iterator<Entry> entries = dn.getEntries(); entries.hasNext();) {\r
+ Entry entry = entries.next();\r
+ //System.out.println(oleName + "." + entry.getName());\r
+ }\r
+ } else {\r
+ // There is no DirectoryEntry\r
+ // Recover the object's data from the HSSFObjectData instance.\r
+ byte[] objectData = obj.getObjectData();\r
+ }\r
+ }\r
+ }\r
+ workbook.close();\r
+ }\r
+}\r
+++ /dev/null
-/* ====================================================================\r
- Licensed to the Apache Software Foundation (ASF) under one or more\r
- contributor license agreements. See the NOTICE file distributed with\r
- this work for additional information regarding copyright ownership.\r
- The ASF licenses this file to You under the Apache License, Version 2.0\r
- (the "License"); you may not use this file except in compliance with\r
- the License. You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.hssf.usermodel.examples;\r
-\r
-import java.io.FileInputStream;\r
-import java.util.Iterator;\r
-\r
-import org.apache.poi.hslf.usermodel.HSLFSlideShow;\r
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;\r
-import org.apache.poi.hssf.usermodel.HSSFObjectData;\r
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
-import org.apache.poi.hwpf.HWPFDocument;\r
-import org.apache.poi.poifs.filesystem.DirectoryNode;\r
-import org.apache.poi.poifs.filesystem.Entry;\r
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;\r
-\r
-/**\r
- * Demonstrates how you can extract embedded data from a .xls file\r
- */\r
-public class EmeddedObjects {\r
- @SuppressWarnings("unused")\r
- public static void main(String[] args) throws Exception {\r
- POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));\r
- HSSFWorkbook workbook = new HSSFWorkbook(fs);\r
- for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {\r
- //the OLE2 Class Name of the object\r
- String oleName = obj.getOLE2ClassName();\r
- if (oleName.equals("Worksheet")) {\r
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
- HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false);\r
- //System.out.println(entry.getName() + ": " + embeddedWorkbook.getNumberOfSheets());\r
- embeddedWorkbook.close();\r
- } else if (oleName.equals("Document")) {\r
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
- HWPFDocument embeddedWordDocument = new HWPFDocument(dn);\r
- //System.out.println(entry.getName() + ": " + embeddedWordDocument.getRange().text());\r
- } else if (oleName.equals("Presentation")) {\r
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
- HSLFSlideShow embeddedPowerPointDocument = new HSLFSlideShow(new HSLFSlideShowImpl(dn));\r
- //System.out.println(entry.getName() + ": " + embeddedPowerPointDocument.getSlides().length);\r
- } else {\r
- if(obj.hasDirectoryEntry()){\r
- // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is\r
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();\r
- for (Iterator<Entry> entries = dn.getEntries(); entries.hasNext();) {\r
- Entry entry = entries.next();\r
- //System.out.println(oleName + "." + entry.getName());\r
- }\r
- } else {\r
- // There is no DirectoryEntry\r
- // Recover the object's data from the HSSFObjectData instance.\r
- byte[] objectData = obj.getObjectData();\r
- }\r
- }\r
- }\r
- workbook.close();\r
- }\r
-}\r