1.新建一個windows窗體程序

2. 引入包WinWordControl.dll
3.添加引用

4.引入組件WinWordControl組件

5.主界面上加入按鈕 ,opendialog, winwordcontrol
第一個為winwordcontrol
第二個為button1
第三個為opendialog
如圖

6.讀取顯示
一,直接讀取顯示
form1寫法,
using System;
using System.Windows.Forms;
namespace wordtest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string dir = Environment.CurrentDirectory + "\\debug或release目錄下的文件名.doc";
winWordControl1.LoadDocument(dir);
}
}
}
二,間接顯示
form1寫法,
using System;
using System.Windows.Forms;
namespace wordtest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
winWordControl1.LoadDocument(openFileDialog1.FileName);
MessageBox.Show(openFileDialog1.FileName);
}
}
}
}
7.完成,間接顯示效果如圖

