检测受密码保护的单词文件

程序员

我正在使用“ netoffice”库从Word文件中提取文本。这应该是自动化过程。

但是,当单词文件受密码保护时,将显示警报窗口,因此用户需要输入密码。由于这是自动过程,因此用户无需输入密码,程序将在此处停止。

如何检测该单词文件是否受“ netoffice”密码保护,并且如果无法实现,如何禁用警报窗口?

我尝试将DisplayAlerts设置为WdAlertLevel.wdAlertsNone,但是它不起作用。

乔治·贝索斯(Giorgos Betsos)

以下代码段将帮助您跳过受密码保护的文件:

        int iFilesWithPassword = 0;
        Factory.Initialize();
        Application wordApplication = new NetOffice.WordApi.Application();

        try
        {
            // Attempt to open existing document. If document is not password protected then 
            // passwordDocument parameter is simply ignored. If document is password protected
            // then an error is thrown and caught by the catch clause the follows, unless 
            // password is equal to "#$nonsense@!"!                              
            Document newDocument = wordApplication.Documents.Open(@"C:\Users\Giorgos\Desktop\myNextFile.doc",
                                                                  confirmConversions: false,
                                                                  addToRecentFiles: false,
                                                                  readOnly: false,
                                                                  passwordDocument: "#$nonsense@!");



            // read text of document
            string text = newDocument.Content.Text;
        }
        catch(Exception e)
        {
            Exception inner = e.InnerException;

            if (inner != null && inner.InnerException != null)
            {
                inner = inner.InnerException;
                string sErrorMessage = inner.Message;

                if (sErrorMessage.Contains("The password is incorrect."))
                {
                    iFilesWithPassword++;
                }
            }

        }
        finally
        {
            // close word and dispose reference 
            wordApplication.Quit();
            wordApplication.Dispose();
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jQuery Plupload在上载时检测加密(受密码保护)的文件

来自分类Dev

如何使用python打开受密码保护的Excel文件?

来自分类Dev

如何使用PHPExcel读取受密码保护的Excel文件?

来自分类Dev

忽略受密码保护的Excel文件

来自分类Dev

如何使pdf文件受密码保护?

来自分类Dev

使用Java读取受密码保护的Excel文件(.xlsx)

来自分类Dev

检测受密码保护的单词文件

来自分类Dev

特定的Rails路由受密码保护

来自分类Dev

创建受密码保护的文件

来自分类Dev

从受密码保护的Excel文件到Python对象

来自分类Dev

使用Powershell跳过受密码保护的PowerPoint文件

来自分类Dev

在vbsript中解压缩受密码保护的文件

来自分类Dev

Mac OSX中受密码保护的文件

来自分类Dev

如何提取受密码保护的.7z文件?

来自分类Dev

在C / C ++中检测受密码保护的MS Office文件

来自分类Dev

忽略受密码保护的Excel文件

来自分类Dev

如何检测7zip文件是否受密码保护?

来自分类Dev

受密码保护的zip文件的安全性如何?

来自分类Dev

Excel无法打开受密码保护的.ods文件

来自分类Dev

受密码保护的域名glassfish

来自分类Dev

LibreOffice是否加密受密码保护的文件

来自分类Dev

Android中受密码保护的屏幕

来自分类Dev

如何更新受密码保护的.7z归档文件的密码?

来自分类Dev

PHPMailer受密码保护的附件

来自分类Dev

宏以保存受密码保护的文件

来自分类Dev

创建加密(受密码保护)的zip文件

来自分类Dev

与受密码保护的Jupyter / api交互

来自分类Dev

使用 Process.Start 打开受密码保护的 Excel 文件 - 不要等待密码

来自分类Dev

Powershell 编辑多个受密码保护的 Word 文件

Related 相关文章

热门标签

归档