如何使用c#在windows窗体中打开word文档?

问题描述:

我想打开word文档,它会在我的机器上运行但是在发布word文件后单独打开。

I want to open word document inside form it will work on my machine but after publish word file open separately.

我猜你是使用InterOp库,它要求各种Office应用程序驻留在执行应用程序代码的系统上。 Microsoft已明确表示此库仅应用于本地计算机开发(即Windows应用程序),不应用于Web应用程序。



对于Web应用程序,您可以使用DocumentFormat.OpenXML库复制此行为。您需要在此处下载该扩展程序: https://www.nuget.org/packages/DocumentFormat.OpenXml/ [ ^ ]



网上有一些教程可供使用。
I'm guessing that you're using the InterOp library, which requires that the various Office applications are resident on the system that is executing the application code. Microsoft has made clear that this library should only be used for local machine development (ie Windows applications) and should not be used for Web applications.

For Web Applications you can replicate this behaviour using the DocumentFormat.OpenXML library. You will need to download the extension for it here: https://www.nuget.org/packages/DocumentFormat.OpenXml/[^]

There are some tutorials for use around the web.