c# 调用word问题 我现在想用c# 调用word文档,怎么实现啊?有没有高手给个完整的例子。就是实现我点击某个按钮,然后弹出一个word 对话框。提示你打开,你开后就可以看到完整的word了 。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.Diagnostics.Process.Start("word路径"); if (openDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK){ System.Diagnostics.Process.Start(openDialog1.FileName);} 如果只是要打开,你用process调用word程序打开指定文件就好了。 我使用过C#word控件WinWordControl加载一个word文件,不知道适不适合你的需求:这里查看:C# word控件编程 Word.Application appWord = new Word.Application();Word.Document docWord = new Word.Document();docWord = appWord.Documents.Open("L:\\SWPPP\\SWPPPBookMerge.doc"); 就是打开WORD文档,显示已经存在的WORD文档的内容! 怎么把WORD的内容嵌入到窗体中,使用什么控件啊? C#word控件WinWordControl加载一个word文件 string flPath = "D:/a.doc";string flNm = flPath.Substring(flPath.LastIndexOf("/") + 1, flPath.Length - flPath.LastIndexOf("/") - 1);string enflNm = Server.UrlEncode(flNm);enflNm = enflNm.Replace("+", "%20");Response.Clear();Response.ContentType = "application/msword";Response.AddHeader("Content-Disposition","attachment;filename=" + enflNm);Response.Charset = "gb2312";string filePath = ""; //物理路径filePath = Server.MapPath(flPath);FileStream myFile = File.OpenRead(filePath); //读取文件进入FileStreambyte[] fileCont = new byte[myFile.Length];myFile.Read(fileCont, 0, (int)myFile.Length); //将文件流中的内容转成byte数组Response.BinaryWrite(fileCont);myFile.Close();Response.End(); WinWordControl 控件是免费的 吗?在哪获取 我想只显示word内容。而且客户端只能浏览,不能修改内容,如何实现啊? 要只显示word 就直接指定路径即可 代码自己查 要是完整的操作的话 我在网页中嵌入 一般用NTKO控件 不设保存 显示word的控件 enable 在WinForm中嵌入Word和Excel 在 Visual C# .NET 中新建一个 Windows 应用程序项目。默认情况下会创建 Form1。 在工具菜单上,单击自定义工具箱以打开自定义工具箱对话框。在 COM 组件选项卡上,添加一个对 Microsoft WebBrowser 的引用。单击确定,将 WebBrowser 控件添加到 Windows 窗体工具箱。WebBrowser 控件会显示出来,并且在工具箱中带有 Explorer(资源管理器)字样。 使用该工具箱向 Form1 添加一个 WebBrowser 控件、一个 OpenFileDialog 控件和一个 CommandButton 按钮。这就会向 Form1 类添加 AxWebBrowser1、OpenFileDialog1 和 Button1 成员变量。 在 Form1 上,双击 button1。这就会向 Form1 添加 Button1_Click 事件。 在 Form1 的代码窗口中,向列表添加以下命名空间:using System.Reflection; 如下所示在 Form1 类中定义一个私有成员:private Object oDocument; 在 Form1 类的 InitializeComponent 方法的末尾,添加以下代码以处理 Form1_Load、Form1_Closed 和 axWebBrowser1_NavigateComplete2 事件:this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2); this.Load += new System.EventHandler(this.Form1_Load); this.Closed += new System.EventHandler(this.Form1_Closed); 将下面的代码private void button1_Click(object sender, System.EventArgs e) { } 替换为: private void button1_Click(object sender, System.EventArgs e) { String strFileName; //Find the Office document. openFileDialog1.FileName = ""; openFileDialog1.ShowDialog(); strFileName = openFileDialog1.FileName; //If the user does not cancel, open the document. if(strFileName.Length != 0) { Object refmissing = System.Reflection.Missing.Value; oDocument = null; axWebBrowser1.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing); } } public void Form1_Load(object sender, System.EventArgs e) { button1.Text = "Browse"; openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ; openFileDialog1.FilterIndex = 1; } public void Form1_Closed(object sender, System.EventArgs e) { oDocument = null; } public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) { //Note: You can use the reference to the document object to // automate the document server. 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() ); } 按 F5 键运行该项目。单击浏览后,会出现打开对话框,您可以使用该对话框浏览到 Word 文档、Excel 工作表或 PowerPoint 演示文稿。选择任一文件,然后单击打开。文档在 WebBrowser 控件内打开,并出现一个显示有 Office 文档服务器名称的消息框。 这个appWord.Documents.Open 里边参数不对吧? LinkButton控件点击刷新页面问题 lock的作用是什么 lock的对象都能是哪些 学C#的问题 我想自己做个小项目大家提议做个什么 一道面试题! winfrom读取Xml并且输出问题---急 C# 结构 菜鸟问题:如何在C#中调用DLL动态链接库,并使用里面的内置方法(有VB代码,不知道如何换成C#) 我之前用的是visual studio6.0,现安装D版.net,却失败:(请教如何解决 C#读文本文件中的汉字出错!怎么办 简单C#多线程问题,有问题请教高手 C# 创建excel并保存
System.Diagnostics.Process.Start("word路径");
{
System.Diagnostics.Process.Start(openDialog1.FileName);
}
不知道适不适合你的需求:
这里查看:C# word控件编程
Word.Application appWord = new Word.Application();
Word.Document docWord = new Word.Document();docWord = appWord.Documents.Open("L:\\SWPPP\\SWPPPBookMerge.doc");
C#word控件WinWordControl加载一个word文件
string flNm = flPath.Substring(flPath.LastIndexOf("/") + 1, flPath.Length - flPath.LastIndexOf("/") - 1);
string enflNm = Server.UrlEncode(flNm);
enflNm = enflNm.Replace("+", "%20");
Response.Clear();
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=" + enflNm);
Response.Charset = "gb2312";
string filePath = ""; //物理路径filePath = Server.MapPath(flPath);
FileStream myFile = File.OpenRead(filePath); //读取文件进入FileStream
byte[] fileCont = new byte[myFile.Length];
myFile.Read(fileCont, 0, (int)myFile.Length); //将文件流中的内容转成byte数组
Response.BinaryWrite(fileCont);
myFile.Close();
Response.End();
不设保存 显示word的控件 enable
在WinForm中嵌入Word和Excel
在 Visual C# .NET 中新建一个 Windows 应用程序项目。默认情况下会创建 Form1。
在工具菜单上,单击自定义工具箱以打开自定义工具箱对话框。在 COM 组件选项卡上,添加一个对 Microsoft WebBrowser 的引用。单击确定,将 WebBrowser 控件添加到 Windows 窗体工具箱。WebBrowser 控件会显示出来,并且在工具箱中带有 Explorer(资源管理器)字样。
使用该工具箱向 Form1 添加一个 WebBrowser 控件、一个 OpenFileDialog 控件和一个 CommandButton 按钮。这就会向 Form1 类添加 AxWebBrowser1、OpenFileDialog1 和 Button1 成员变量。
在 Form1 上,双击 button1。这就会向 Form1 添加 Button1_Click 事件。
在 Form1 的代码窗口中,向列表添加以下命名空间:using System.Reflection;
如下所示在 Form1 类中定义一个私有成员:private Object oDocument;
在 Form1 类的 InitializeComponent 方法的末尾,添加以下代码以处理 Form1_Load、Form1_Closed 和 axWebBrowser1_NavigateComplete2 事件:this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
将下面的代码private void button1_Click(object sender, System.EventArgs e)
{
}
替换为: private void button1_Click(object sender, System.EventArgs e)
{
String strFileName;
//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
//If the user does not cancel, open the document.
if(strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing);
}
}
public void Form1_Load(object sender, System.EventArgs e)
{
button1.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ;
openFileDialog1.FilterIndex = 1;
}
public void Form1_Closed(object sender, System.EventArgs e)
{
oDocument = null;
}
public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
//Note: You can use the reference to the document object to
// automate the document server.
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() );
}
按 F5 键运行该项目。单击浏览后,会出现打开对话框,您可以使用该对话框浏览到 Word 文档、Excel 工作表或 PowerPoint 演示文稿。选择任一文件,然后单击打开。文档在 WebBrowser 控件内打开,并出现一个显示有 Office 文档服务器名称的消息框。
这个appWord.Documents.Open 里边参数不对吧?