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.完成,间接显示效果如图