如何在项目中引用 Word 文档

本文关键字:引用 Word 文档 项目 | 更新日期: 2023-09-27 17:56:13

我想在我的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文件)中引用 Word 文档?

如何在项目中引用 Word 文档

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

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

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

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