You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 07:35:23