Interop.Word Documents.Open 为空

问题描述 投票:0回答:2

我正在尝试打开 .docx 文件并使用 Interop.Word.Application 将其转换为 PDF。它作为控制台应用程序工作,但如果我在我的 Web 应用程序中使用它,它就不起作用。我试图查看文件夹的权限。我给了“网络服务”完全控制权,但我仍然得到未在 word.Documents.Open 中设置的对象引用。你能告诉我可能是什么问题吗?我被这个错误困住了。请告诉我。我感谢任何建议。谢谢。

    Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

    object oMissing = System.Reflection.Missing.Value;

    word.Visible = false;
    word.ScreenUpdating = false;
    string fileName = @"c:\OUTPUT\test.docx");
    Document doc = word.Documents.Open(filename, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        doc.Activate();
c# asp.net ms-word asp.net-4.0 openxml
2个回答
73
投票

如果您仍在寻找答案,我刚刚为我的项目找到了它。

打开 DCOM 配置设置:

  1. 开始 ->
    dcomcnfg.exe
  2. 电脑
  3. 本地电脑
  4. 配置 DCOM
  5. 搜索
    Microsoft Word 97-2003 Documents
    -> 属性

选项卡

Identity
,从
Launching User
更改为
Interactive User


30
投票

试试这个;它可能对你有帮助。

在里面新建一个“Desktop”目录

  • "C:\Windows\SysWOW6

© www.soinside.com 2019 - 2024. All rights reserved.