【问题标题】:How do I reference a word document in my project如何在我的项目中引用 word 文档
【发布时间】:2013-01-25 14:34:25
【问题描述】:

我想在我的 Visual Studio 项目中使用 Word 文件进行编辑并返回该文件。

Microsoft.Office.Interop.Word.Document tempDoc = null;
try
{
    object missing = System.Reflection.Missing.Value;
    Application wordApp = new Application();

    //I have a copy on C: and this works.
    object useFileName = "C:\\WordFile.doc";

    object readOnly = false;
    object isVisible = false;
    wordApp.Visible = false;
    tempDoc = wordApp.Documents.Open(ref useFileName, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref isVisible, ref missing, ref missing,
        ref missing, ref missing);
    ...
    }
    return tempDoc;

如何在我的项目中引用word文档(Content/Documents/WordFile)?

【问题讨论】:

  • @Freeman: 因为ref 参数修饰符需要我想象的引用变量
  • 你的想象力说明了真相。
  • 不要在 ASP.NET 应用程序中使用 Office Interop。

标签: c# asp.net .net visual-studio-2010


【解决方案1】:

也许使用Server.MapPath 指定映射到物理目录的相对或虚拟路径。

Server.MapPath("~/Content/Documents/WordFile")

【讨论】:

  • 这实际上是我想要的。谢谢
【解决方案2】:

您可以从以下位置获取执行代码的位置 System.Reflection.Assembly.GetExecutingAssembly().Location;

或者将文档位置放在配置文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多