C# winform如何实现在控件中显示word文档?

yuchengxujieyuan 2011-04-02 04:19:30
这是我在网上查到的代码,不知道为什么无法显示在控件里,而是直接代开了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());

}
}
}
...全文
1215 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuchengxujieyuan 2011-04-02
  • 打赏
  • 举报
回复
这个是需要花钱的吧?
crackdung 2011-04-02
  • 打赏
  • 举报
回复
用它吧

網站
yuchengxujieyuan 2011-04-02
  • 打赏
  • 举报
回复
没有别的法子吗?
yuchengxujieyuan 2011-04-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 yuchengxujieyuan 的回复:]
这是我在网上查到的代码,不知道为什么无法显示在控件里,而是直接代开了word文档
请高手指点!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using S……
[/Quote]

webBrowser控件
calmzeal 2011-04-02
  • 打赏
  • 举报
回复
你用的WebBroswer不能达到这个要求

需要word容器组件
目前国内有几家做这个 基本都是收费的
我们用的重庆软航的NTKO 还蛮好用的 你可以试试看

lcdsda 2011-04-02
  • 打赏
  • 举报
回复
没试过,帮顶,顺带问一句,显示在winform里面的哪种控件啊?

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧