且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不使用Office互操作库的情况下以编程方式检测Office文档(Word,Excel)中是否存在任何宏?

更新时间:2023-09-10 14:24:04

如果它是.docx,xl​​sx等,它将不会有宏。 (您可能需要充分打开该文件以确保它不是某人重命名为.docx扩展名的.doc。)

Well if it is a .docx, xlsx, etc it won't have macros. (you might need to open the file sufficiently to make sure it isn't a .doc that someone renamed to have a .docx extension).

如果是.doc(或类似)前台2007格式),事情变得更加艰难。  我们的电子邮件系统只是假设.doc文件有宏并隔离这些文件。

If it is a .doc (or similar pre office 2007 format), things are tougher.  Our email system just assumes that .doc files have macros and quarantines those files.

如果要查看.doc,您可能需要某种第三方库来打开该文件并告诉您是否有宏,因为您可能不想自己编写.doc / .xls解析器。

If you want to examine .doc you will probably want a 3rd party library of some sort to open up the file and tell you if you have macros, since you probably don't want to write a .doc/.xls parser yourself.