Package org.apache.poi.poifs.macros
Class VBAMacroReader
java.lang.Object
org.apache.poi.poifs.macros.VBAMacroReader
- All Implemented Interfaces:
Closeable,AutoCloseable
Finds all VBA Macros in an office file (OLE2/POIFS and OOXML/OPC), and returns them.
NOTE: This does not read macros from .ppt files. See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF() in the scratchpad module for an example of how to do this. Patches that make macro extraction from .ppt more elegant are welcomed!
- Since:
- 3.15-beta2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidfindMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules) Recursively traverses directory structure rooted at dir.protected voidfindModuleNameMap(DirectoryNode node, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap modules) protected voidfindProjectProperties(DirectoryNode node, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap modules) Reads all macros from all modules of the opened office file.protected voidreadMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules) Reads VBA Project modules from a VBA Project directory located at macroDir into modules.protected voidreadNameMapRecords(InputStream is, Map<String, String> moduleNames, Charset charset) protected voidreadProjectProperties(DocumentInputStream dis, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap modules)
-
Field Details
-
VBA_PROJECT_OOXML
- See Also:
-
VBA_PROJECT_POIFS
- See Also:
-
-
Constructor Details
-
VBAMacroReader
- Throws:
IOException
-
VBAMacroReader
- Throws:
IOException
-
VBAMacroReader
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
readMacroModules
- Throws:
IOException
-
readMacros
Reads all macros from all modules of the opened office file.- Returns:
- All the macros and their contents
- Throws:
IOException- Since:
- 3.15-beta2
-
findMacros
Recursively traverses directory structure rooted at dir. For each macro module that is found, the module's name and code are added to modules.- Parameters:
dir- The directory of entries to look atmodules- The resulting map of modules- Throws:
IOException- If reading the VBA module fails- Since:
- 3.15-beta2
-
readMacros
protected void readMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules) throws IOException Reads VBA Project modules from a VBA Project directory located at macroDir into modules.- Throws:
IOException- Since:
- 3.15-beta2
-
findProjectProperties
protected void findProjectProperties(DirectoryNode node, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException- Throws:
IOException
-
findModuleNameMap
protected void findModuleNameMap(DirectoryNode node, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException- Throws:
IOException
-
readNameMapRecords
protected void readNameMapRecords(InputStream is, Map<String, String> moduleNames, Charset charset) throws IOException- Throws:
IOException
-
readProjectProperties
protected void readProjectProperties(DocumentInputStream dis, Map<String, String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException- Throws:
IOException
-