I wanted to check if the uploaded word document has macros in it. The document has the extension (.doc). How can I perform this using phpdocx?
I wanted to check if the uploaded word document has macros in it. The document has the extension (.doc). How can I perform this using phpdocx?
Hello,
Macros can be detected by phpdocx when using DOCX documents. In the case of the old DOC documents, maybe you can transform DOC to DOCX using the conversion plugin (https://www.phpdocx.com/api-documentation/format-conversion/convert-Word-docx-into-pdf-with-PHP) and then use phpdocx to check if the DOCX contains macros.
If you send to contact[at]phpdocx.com a DOC document sample you are using, we'll check it.
Regards.
Thank you. What method in phpdocx can be leveraged to detect macros in a DOCX file?
Hello,
The easiest approach is using the getWordFiles method to check if the DOCX/DOCM file contains a macro file. For example:
$docx = new CreateDocxFromTemplate('fileMacros.docm');
$contentsVbaData = $docx->getWordFiles('word/vbaData.xml');
$contentsVbaProjectData = $docx->getWordFiles('word/vbaProject.bin');
if ($contentsVbaData || $contentsVbaProjectData) {
echo 'Macro file found' . PHP_EOL;
}
Regards.