使用Microsoft.Office.Interop.Word时单个文档触发登录弹窗问题求助
问题:Interop.Word打开特定docx文件时弹出登录对话框
我开发了一款利用Microsoft.Office.Interop.Word访问.docx文件并将其转换为.txt格式的应用程序。该程序处理大部分.docx文件都正常,但有一个特定文档例外:每当程序尝试打开该文档时,都会弹出登录对话框。值得注意的是,该文档并未设置密码保护,且直接用Word打开它时没有任何问题。必须关闭凭据对话框或输入正确凭据才能继续,但下次处理该文件时弹窗仍会出现。我困惑于为何只有这个文件会触发登录弹窗,尝试过使用Open和OpenNoRepairDialog方法解决问题,代码示例如下:
Application app = new Application { DisplayAlerts = WdAlertLevel.wdAlertsNone }; WdSaveFormat saveFormat = WdSaveFormat.wdFormatText; string sourceFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "oddFile.docx"); var targetFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "oddFile.txt"); try { //app.Documents.Open(sourceFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); app.Documents.OpenNoRepairDialog(sourceFile, false, false, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, WdOpenFormat.wdOpenFormatAuto, Type.Missing, Type.Missing, true, Type.Missing, false); app.ActiveDocument.SaveAs(targetFile, saveFormat); } catch (Exception) { } finally { app.ActiveDocument.Close(); app.Quit(); app = null; }
C#代码打开该异常文件时弹出的对话框如下:

内容的提问来源于stack exchange,提问作者Simant
相关产品推荐
相关产品推荐

