以编程方式打开位于C#计算机中的Word文档 [英] Programmatically Open Word Document Located in the Computer in C#
本文介绍了以编程方式打开位于C#计算机中的Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用WinForms.我有一个带有按钮的表格.
I'm using WinForms. I have a form that has a button.
目标:在按钮上单击:打开Word文档.文件路径被硬编码到程序中的位置.我不希望用户必须找到word文档.
Goal: On button click: Open up a word document. Where the file path is hard coded into the program. I don't want the users to have to locate the word document.
问题:我收到此错误消息.当我编写代码时,在应用程序"下出现红色错误行.
Problem: I receive this error message. When I wrote my code, I get a red error line under 'Application'.
private void button1_Click(object sender, EventArgs e)
{
this.Application.Documents.Open(@"C:\Test\NewDocument.docx", ReadOnly:true)
}
推荐答案
首先将Microsoft.Office.Interop.Word
的dll添加到您的引用中,然后添加以下内容:
first add the dll of Microsoft.Office.Interop.Word
to your references then add this:
using Microsoft.Office.Interop.Word;
并使用以下代码:
Application ap = new Application();
Document document = ap.Documents.Open(@"C:\Test\NewDocument.docx");
这篇关于以编程方式打开位于C#计算机中的Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文