/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param dir a DirectoryNode containing your workbook * * @throws IOException if the workbook contained errors */ public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException { // some old documents have "WORKBOOK" or "BOOK" String name = null; Set<String> entryNames = dir.getEntryNames(); for (String potentialName : WORKBOOK_DIR_ENTRY_NAMES) { if (entryNames.contains(potentialName)) { name = potentialName; break; } } // If in doubt, go for the default if (name == null) { name = WORKBOOK_DIR_ENTRY_NAMES[0]; } InputStream in = dir.createDocumentInputStream(name); try { processEvents(req, in); } finally { in.close(); } }
@SuppressWarnings("unchecked") public static <T extends POITextExtractor> T createExtractor(DirectoryNode poifsDir) throws IOException, OpenXML4JException, XmlException { // First, check for OOXML for (String entryName : poifsDir.getEntryNames()) { if (entryName.equals("Package")) { OPCPackage pkg = OPCPackage.open(poifsDir.createDocumentInputStream("Package")); return (T)createExtractor(pkg); } } // If not, ask the OLE2 code to check, with Scratchpad if possible return (T)OLE2ExtractorFactory.createExtractor(poifsDir); }
public static String getWorkbookDirEntryName(DirectoryNode directory) { for(String wbName : WORKBOOK_DIR_ENTRY_NAMES) { if(directory.hasEntry(wbName)) { return wbName; } } // check for an encrypted .xlsx file - they get OLE2 wrapped try { directory.getEntry(Decryptor.DEFAULT_POIFS_ENTRY); throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " + "It must be decrypted before use by XSSF, it cannot be used by HSSF"); } catch (FileNotFoundException e) { // fall through } // check for previous version of file format try { 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) { // fall through } throw new IllegalArgumentException("The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. " + "Is it really an excel file? Had: " + directory.getEntryNames()); }
/** * Reads VBA Project modules from a VBA Project directory located at * <tt>macroDir</tt> into <tt>modules</tt>. * * @since 3.15-beta2 */ protected void readMacros(DirectoryNode macroDir, ModuleMap modules) throws IOException { //bug59858 shows that dirstream may not be in this directory (\MBD00082648\_VBA_PROJECT_CUR\VBA ENTRY NAME) //but may be in another directory (\_VBA_PROJECT_CUR\VBA ENTRY NAME) //process the dirstream first -- "dir" is case insensitive for (String entryName : macroDir.getEntryNames()) { if ("dir".equalsIgnoreCase(entryName)) { processDirStream(macroDir.getEntry(entryName), modules); break; } } for (Entry entry : macroDir) { if (! (entry instanceof DocumentNode)) { continue; } String name = entry.getName(); DocumentNode document = (DocumentNode)entry; if (! "dir".equalsIgnoreCase(name) && !startsWithIgnoreCase(name, "__SRP") && !startsWithIgnoreCase(name, "_VBA_PROJECT")) { // process module, skip __SRP and _VBA_PROJECT since these do not contain macros readModuleFromDocumentStream(document, name, modules); } } }
throw new UnsupportedFormatException("Unsupported QuattroPro file format. " + "Looking for OLE entry \"" + OLE_DOCUMENT_NAME + "\". Found: " + (rootNode == null ? "null" : rootNode.getEntryNames()));
/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param dir a DirectoryNode containing your workbook * * @throws IOException if the workbook contained errors */ public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException { // some old documents have "WORKBOOK" or "BOOK" String name = null; Set<String> entryNames = dir.getEntryNames(); for (String potentialName : WORKBOOK_DIR_ENTRY_NAMES) { if (entryNames.contains(potentialName)) { name = potentialName; break; } } // If in doubt, go for the default if (name == null) { name = WORKBOOK_DIR_ENTRY_NAMES[0]; } InputStream in = dir.createDocumentInputStream(name); try { processEvents(req, in); } finally { in.close(); } }
@SuppressWarnings("unchecked") public static <T extends POITextExtractor> T createExtractor(DirectoryNode poifsDir) throws IOException, OpenXML4JException, XmlException { // First, check for OOXML for (String entryName : poifsDir.getEntryNames()) { if (entryName.equals("Package")) { OPCPackage pkg = OPCPackage.open(poifsDir.createDocumentInputStream("Package")); return (T)createExtractor(pkg); } } // If not, ask the OLE2 code to check, with Scratchpad if possible return (T)OLE2ExtractorFactory.createExtractor(poifsDir); }
/** * Reads VBA Project modules from a VBA Project directory located at * <tt>macroDir</tt> into <tt>modules</tt>. * * @since 3.15-beta2 */ protected void readMacros(DirectoryNode macroDir, ModuleMap modules) throws IOException { //bug59858 shows that dirstream may not be in this directory (\MBD00082648\_VBA_PROJECT_CUR\VBA ENTRY NAME) //but may be in another directory (\_VBA_PROJECT_CUR\VBA ENTRY NAME) //process the dirstream first -- "dir" is case insensitive for (String entryName : macroDir.getEntryNames()) { if ("dir".equalsIgnoreCase(entryName)) { processDirStream(macroDir.getEntry(entryName), modules); break; } } for (Entry entry : macroDir) { if (! (entry instanceof DocumentNode)) { continue; } String name = entry.getName(); DocumentNode document = (DocumentNode)entry; if (! "dir".equalsIgnoreCase(name) && !startsWithIgnoreCase(name, "__SRP") && !startsWithIgnoreCase(name, "_VBA_PROJECT")) { // process module, skip __SRP and _VBA_PROJECT since these do not contain macros readModuleFromDocumentStream(document, name, modules); } } }
public static String getWorkbookDirEntryName(DirectoryNode directory) { for(String wbName : WORKBOOK_DIR_ENTRY_NAMES) { if(directory.hasEntry(wbName)) { return wbName; } } // check for an encrypted .xlsx file - they get OLE2 wrapped try { directory.getEntry(Decryptor.DEFAULT_POIFS_ENTRY); throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " + "It must be decrypted before use by XSSF, it cannot be used by HSSF"); } catch (FileNotFoundException e) { // fall through } // check for previous version of file format try { 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) { // fall through } throw new IllegalArgumentException("The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. " + "Is it really an excel file? Had: " + directory.getEntryNames()); }
throw new UnsupportedFormatException("Unsupported QuattroPro file format. " + "Looking for OLE entry \"" + OLE_DOCUMENT_NAME + "\". Found: "+ rootNode.getEntryNames());
throw new UnsupportedFormatException("Unsupported QuattroPro file format. " + "Looking for OLE entry \"" + OLE_DOCUMENT_NAME + "\". Found: " + (rootNode == null ? "null" : rootNode.getEntryNames()));