C# winform如何实现在控件中显示word文档?
这是我在网上查到的代码,不知道为什么无法显示在控件里,而是直接代开了word文档
请高手指点!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace TestShowWordOnForm
{
public partial class Form1 : Form
{
private Object oDocument;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String strFileName;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
if (strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
}
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
openFileDialog1.FilterIndex = 1;
}
private void Form1_Closed(object sender, EventArgs e)
{
oDocument = null;
}
private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
Object o = e.pDisp;
oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);
Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);
Object oName = o.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oApplication, null);
MessageBox.Show("File opened by: " + oName.ToString());
}
}
}
请高手指点!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace TestShowWordOnForm
{
public partial class Form1 : Form
{
private Object oDocument;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String strFileName;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
if (strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
}
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
openFileDialog1.FilterIndex = 1;
}
private void Form1_Closed(object sender, EventArgs e)
{
oDocument = null;
}
private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
Object o = e.pDisp;
oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);
Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);
Object oName = o.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oApplication, null);
MessageBox.Show("File opened by: " + oName.ToString());
}
}
}
...全文
相关推荐
WinForm嵌入Word文档控件开发
因为看到论坛中很多人想把Word文档中嵌入WinForm中,虽然WebBrowser控件可以实现这个功能,但是使用这个控件不能对Word进行很好的控制,这个资源通过自定义控件来实现嵌入Word文档,大家可以下载下来研究下的
c# winform 显示word
c# winform 显示word 解决了 不能在winform窗体上显示word文档的问题 该程序能完美的将word文档显示在winform窗体中
C# WinForm窗体加载Excel、Word文件
C#代码,通过在WinForm窗体中直接打开Excel或Word文件,包含源代码,步步亿佰公司用来做测试用的,分享给大家做参考
c# word编辑器,winform 编辑器,word控件,word相关大全
c# word编辑器,winform 编辑器,word控件,word相关大全
C# winform 使用DsoFramer 创建 显示office 文档
C# winform 使用第三方软件DsoFramer 创建 显示office 文档, office文档嵌入winform窗体内进行编辑。


