public class VBAMacroReader extends Object implements Closeable
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!
| Modifier and Type | Class and Description |
|---|---|
protected static class |
VBAMacroReader.ModuleImpl |
protected static class |
VBAMacroReader.ModuleMap |
| Modifier and Type | Field and Description |
|---|---|
protected static String |
VBA_PROJECT_OOXML |
protected static String |
VBA_PROJECT_POIFS |
| Constructor and Description |
|---|
VBAMacroReader(File file) |
VBAMacroReader(InputStream rstream) |
VBAMacroReader(POIFSFileSystem fs) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected void |
findMacros(DirectoryNode dir,
VBAMacroReader.ModuleMap modules)
Recursively traverses directory structure rooted at
dir. |
protected void |
findModuleNameMap(DirectoryNode node,
Map<String,String> moduleNameMap,
VBAMacroReader.ModuleMap modules) |
protected void |
findProjectProperties(DirectoryNode node,
Map<String,String> moduleNameMap,
VBAMacroReader.ModuleMap modules) |
Map<String,Module> |
readMacroModules() |
Map<String,String> |
readMacros()
Reads all macros from all modules of the opened office file.
|
protected void |
readMacros(DirectoryNode macroDir,
VBAMacroReader.ModuleMap modules)
Reads VBA Project modules from a VBA Project directory located at
macroDir into modules. |
protected void |
readNameMapRecords(InputStream is,
Map<String,String> moduleNames,
Charset charset) |
protected void |
readProjectProperties(DocumentInputStream dis,
Map<String,String> moduleNameMap,
VBAMacroReader.ModuleMap modules) |
protected static final String VBA_PROJECT_OOXML
protected static final String VBA_PROJECT_POIFS
public VBAMacroReader(InputStream rstream) throws IOException
IOExceptionpublic VBAMacroReader(File file) throws IOException
IOExceptionpublic VBAMacroReader(POIFSFileSystem fs)
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic Map<String,Module> readMacroModules() throws IOException
IOExceptionpublic Map<String,String> readMacros() throws IOException
IOExceptionprotected void findMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules) throws IOException
dir.
For each macro module that is found, the module's name and code are
added to modules.dir - The directory of entries to look atmodules - The resulting map of modulesIOException - If reading the VBA module failsprotected void readMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules) throws IOException
macroDir into modules.IOExceptionprotected void findProjectProperties(DirectoryNode node, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException
IOExceptionprotected void findModuleNameMap(DirectoryNode node, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException
IOExceptionprotected void readNameMapRecords(InputStream is, Map<String,String> moduleNames, Charset charset) throws IOException
IOExceptionprotected void readProjectProperties(DocumentInputStream dis, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException
IOException