如何在c#的程序中嵌入word和excel(高分200求)!!!!! http://www.microsoft.com/china/msdn/archives/library/dnexcl2k2/html/odc_offcs.asp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 大哥错了啊我问的是,在c#form中嵌入word和excel,不是问office编程!!! 嵌入word和excel?是什么意思? 使用OLE,MSDN文档里有说明的! 或者使用我以前用过的方法,使用dataset作为中介,方法就是word<->dataset<->controls %@ Page Language="C#" Debug="true" %><%@ Import Namespace="System.Data"%><%@ Import Namespace="System.Data.OleDb"%><script runat="server">private DataSet CreateDataSource(){string strConn;strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source=C:\\Inetpub\\wwwroot\\contacts.xls;"+"Extended Properties=Excel 8.0;";OleDbConnection conn = new OleDbConnection(strConn);OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [ContactList$]", strConn);DataSet myDataSet = new DataSet();myCommand.Fill(myDataSet);return myDataSet;}public void Page_Load(Object sender, EventArgs e){if (!IsPostBack) {mygrid.DataSource = CreateDataSource();mygrid.DataBind();}}</script><center><form runat="server"><asp:datagrid runat="server" AutoGenerateColumns="false"width="500" id="mygrid"><HeaderStyle BorderColor="White" BackColor="black"ForeColor="White"Font-Bold="True"Font-Name="Arial"Font-Size="9" HorizontalAlign="Center"/><ItemStyle BorderColor=""BackColor="#FFFFF0"ForeColor="Black"Font-Name="Arial"Font-Size="8"Font-Bold="False" HorizontalAlign="Center"/><Columns><asp:BoundColumn HeaderText="姓名" ReadOnly="true" DataField="姓名"/><asp:BoundColumn HeaderText="性别" ReadOnly="true" DataField="性别"/><asp:BoundColumn HeaderText="Email" ReadOnly="true" DataField="地址"/></Columns></asp:datagrid></form>试试这个看看能行吗? zfwdf(山水) 稍微给点解释好不?? http://community.csdn.net/Expert/topic/3021/3021597.xml?temp=.9644434 可以在web 中放入 word、excel 的ActiveX 我的意思是,如何在form中出现工具栏和菜单,进行互操作 但是放入EXCEL后只能有一个SHEET,不能实现多个SHEET 你是不是想自动成表格呢如果这样的话你就可以用for循环 我有. C#WinForm + Word 的程序.相对比较简单的. 可以自己写一个嵌入word的控件http://www.codeproject.com/cs/miscctrl/winwordcontrol.asp还可以自己扩展你想要的功能,我就加了一些功能,比如说显示和隐藏工具栏和菜单 to minghao1039(明皓) 能给我你的代码吗?不胜感激!! Visual C# 编程操作Excelhttp://soft.yesky.com/SoftChannel/72342380468109312/20040819/1844435.shtml 用OLE,直接可以在WinForm里链接或嵌入外部程序 转个小弯:把Word文件存到数据库中,然后用'设定输出文件类型(可以更改为word和excel和其它类型,最好和原文件类型一致) Response.ContentType = CType(Session("ContentType"), String) '输出图象文件二进制数制 Response.OutputStream.Write((CType(Session("Image"), Byte())), 0, CType(Session("ImageSize"), Integer)) '输出文字信息 'Response.Write(((CType(Session("Description"), String))).ToCharArray(), 0, (CType(Session("Description"), String)).Length) Response.End()读出来,就可以得到类似http://www.goldgrid.com/Products/Demo/iWebOfficeSign/Ocxasp/DocumentList.asp里演示的那样嵌入到IE里面的效果了 注:所用的Session都是从数据库中读取的并事先履了相应的值 xiaomaoy(小红茂)说的这个好难呀 xiaomaoy(小红茂)大哥说的好难呀 用OFFICE的COM组件 '导入Word Dim wordfile As Object wordfile = CreateObject("Word.Application") wordfile.Visible = True Dim wordfileDoc As New Word.Document wordfileDoc = wordfile.Documents.Open(System.Windows.Forms.Application.StartupPath + "\contract\" + ComboBox1.Text, ReadOnly:=True) wordfileDoc.Range.Find.Execute(FindText:="{合同编号}", ReplaceWith:=dr("contractid").ToString) wordfileDoc.Range.Find.Execute(FindText:="{合同名称}", ReplaceWith:=TextBox1.Text) wordfileDoc.Range.Find.Execute(FindText:="{客户名称}", ReplaceWith:=TextBox2.Text) wordfileDoc.Range.Find.Execute(FindText:="{乙方签约人}", ReplaceWith:=TextBox3.Text) wordfileDoc.Range.Find.Execute(FindText:="{合同金额}", ReplaceWith:=TextBox4.Text) wordfileDoc.Range.Find.Execute(FindText:="{预计毛利额}", ReplaceWith:=TextBox5.Text) wordfileDoc.Range.Find.Execute(FindText:="{主要内容}", ReplaceWith:=dr("content").ToString) wordfileDoc.Range.Find.Execute(FindText:="{所属部门}", ReplaceWith:=TextBox6.Text) wordfileDoc.Range.Find.Execute(FindText:="{添加人}", ReplaceWith:=TextBox7.Text) wordfileDoc.Range.Find.Execute(FindText:="{签单日期}", ReplaceWith:=TextBox8.Text) wordfileDoc.Range.Find.Execute(FindText:="{添加日期}", ReplaceWith:=TextBox9.Text) MyCommand.Connection.Close() 人家问的是如何在c#的程序中嵌入word和excel 使用OFFICE组件建立wordapplication和excelapplication很容易办到如果C#不支持,先用以前的C++做成控件再用也一样,不知你懂不懂,如果你看过VBA就会理解了 using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WinWordTestApp{ /// <summary> /// just testing /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button load; private WinWordControl.WinWordControl winWordControl1; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button Restore; private System.Windows.Forms.Button close; /// <summary> /// needed designer variable /// </summary> private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } /// <summary> /// cleanuup ressources /// </summary> protected override void Dispose( bool disposing ) { // just to be shure! winWordControl1.CloseControl(); if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// /// </summary> private void InitializeComponent() { this.load = new System.Windows.Forms.Button(); this.winWordControl1 = new WinWordControl.WinWordControl(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.button1 = new System.Windows.Forms.Button(); this.Restore = new System.Windows.Forms.Button(); this.close = new System.Windows.Forms.Button(); this.SuspendLayout(); // // load // this.load.Location = new System.Drawing.Point(592, 24); this.load.Name = "load"; this.load.Size = new System.Drawing.Size(56, 32); this.load.TabIndex = 1; this.load.Text = "load"; this.load.Click += new System.EventHandler(this.load_Click); // // winWordControl1 // this.winWordControl1.Dock = System.Windows.Forms.DockStyle.Left; this.winWordControl1.Name = "winWordControl1"; this.winWordControl1.Size = new System.Drawing.Size(560, 389); this.winWordControl1.TabIndex = 2; // // openFileDialog1 // this.openFileDialog1.Filter = "WordDateien (*.doc)|*.doc"; // // button1 // this.button1.Location = new System.Drawing.Point(592, 152); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(56, 32); this.button1.TabIndex = 3; this.button1.Text = "PreActivate"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Restore // this.Restore.Location = new System.Drawing.Point(592, 208); this.Restore.Name = "Restore"; this.Restore.Size = new System.Drawing.Size(56, 32); this.Restore.TabIndex = 4; this.Restore.Text = "Restore Word"; this.Restore.Click += new System.EventHandler(this.Restore_Click); // // close // this.close.Location = new System.Drawing.Point(592, 72); this.close.Name = "close"; this.close.Size = new System.Drawing.Size(56, 32); this.close.TabIndex = 5; this.close.Text = "Close"; this.close.Click += new System.EventHandler(this.close_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(672, 389); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.close, this.Restore, this.button1, this.winWordControl1, this.load}); this.Name = "Form1"; this.Text = "Form1"; this.Activated += new System.EventHandler(this.OnActivate); this.ResumeLayout(false); } #endregion /// <summary> /// main entry for your Application /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void OnActivate(object sender, System.EventArgs e) { } private void load_Click(object sender, System.EventArgs e) { if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { winWordControl1.LoadDocument(openFileDialog1.FileName); } } private void button1_Click(object sender, System.EventArgs e) { winWordControl1.PreActivate(); } private void Restore_Click(object sender, System.EventArgs e) { winWordControl1.RestoreWord(); } private void close_Click(object sender, System.EventArgs e) { winWordControl1.CloseControl(); } }}Interop.Office.dllInterop.VBIDE.dllInterop.Word.dllWinWordControl.dll to calmhawkaaa(风中枫叶)好长的代码呀,给点解释吗 关键是怎么融合word的菜单到winform中啊? to chenczx1(昕) 说说看 c#winform打开网页并post数据到要打开的网页 类、结构、抽象类、接口的区别 win7 x64下flash的843端口telnet 不通 声名变量 小问题 c#的组合下拉列表框能否只选择,禁止用户编辑 DataGird如何正确显示SQL数据库日期格式的数据 C#windows窗体程序调用webService问题 将pdf转换为swf并显示在网页中 关于给网址加上链接的--正则表达式 datagrid数据更新的问题 MSN MESSANGER的中显示消息的文本框是怎么做的啊? 在线给分.急!急!急!急!急!急!急!
我问的是,在c#form中嵌入word和excel,
不是问office编程!!!
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%><script runat="server">private DataSet CreateDataSource(){
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Inetpub\\wwwroot\\contacts.xls;"+
"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [ContactList$]", strConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);
return myDataSet;
}
public void Page_Load(Object sender, EventArgs e){
if (!IsPostBack) {
mygrid.DataSource = CreateDataSource();
mygrid.DataBind();
}}
</script>
<center>
<form runat="server">
<asp:datagrid runat="server" AutoGenerateColumns="false"
width="500" id="mygrid"><HeaderStyle BorderColor="White" BackColor="black"
ForeColor="White"
Font-Bold="True"
Font-Name="Arial"
Font-Size="9" HorizontalAlign="Center"/><ItemStyle BorderColor=""
BackColor="#FFFFF0"
ForeColor="Black"
Font-Name="Arial"
Font-Size="8"
Font-Bold="False" HorizontalAlign="Center"/><Columns><asp:BoundColumn HeaderText="姓名" ReadOnly="true" DataField="姓名"/>
<asp:BoundColumn HeaderText="性别" ReadOnly="true" DataField="性别"/>
<asp:BoundColumn HeaderText="Email" ReadOnly="true" DataField="地址"/>
</Columns></asp:datagrid>
</form>
试试这个看看能行吗?
稍微给点解释好不??
如果这样的话你就可以用for循环
http://www.codeproject.com/cs/miscctrl/winwordcontrol.asp
还可以自己扩展你想要的功能,我就加了一些功能,比如说显示和隐藏工具栏和菜单
能给我你的代码吗?不胜感激!!
http://soft.yesky.com/SoftChannel/72342380468109312/20040819/1844435.shtml
把Word文件存到数据库中,然后用
'设定输出文件类型(可以更改为word和excel和其它类型,最好和原文件类型一致)
Response.ContentType = CType(Session("ContentType"), String)
'输出图象文件二进制数制
Response.OutputStream.Write((CType(Session("Image"), Byte())), 0, CType(Session("ImageSize"), Integer))
'输出文字信息
'Response.Write(((CType(Session("Description"), String))).ToCharArray(), 0, (CType(Session("Description"), String)).Length)
Response.End()
读出来,就可以得到类似
http://www.goldgrid.com/Products/Demo/iWebOfficeSign/Ocxasp/DocumentList.asp
里演示的那样嵌入到IE里面的效果了
所用的Session都是从数据库中读取的并事先履了相应的值
Dim wordfile As Object
wordfile = CreateObject("Word.Application")
wordfile.Visible = True
Dim wordfileDoc As New Word.Document
wordfileDoc = wordfile.Documents.Open(System.Windows.Forms.Application.StartupPath + "\contract\" + ComboBox1.Text, ReadOnly:=True)
wordfileDoc.Range.Find.Execute(FindText:="{合同编号}", ReplaceWith:=dr("contractid").ToString)
wordfileDoc.Range.Find.Execute(FindText:="{合同名称}", ReplaceWith:=TextBox1.Text)
wordfileDoc.Range.Find.Execute(FindText:="{客户名称}", ReplaceWith:=TextBox2.Text)
wordfileDoc.Range.Find.Execute(FindText:="{乙方签约人}", ReplaceWith:=TextBox3.Text)
wordfileDoc.Range.Find.Execute(FindText:="{合同金额}", ReplaceWith:=TextBox4.Text)
wordfileDoc.Range.Find.Execute(FindText:="{预计毛利额}", ReplaceWith:=TextBox5.Text)
wordfileDoc.Range.Find.Execute(FindText:="{主要内容}", ReplaceWith:=dr("content").ToString)
wordfileDoc.Range.Find.Execute(FindText:="{所属部门}", ReplaceWith:=TextBox6.Text)
wordfileDoc.Range.Find.Execute(FindText:="{添加人}", ReplaceWith:=TextBox7.Text)
wordfileDoc.Range.Find.Execute(FindText:="{签单日期}", ReplaceWith:=TextBox8.Text)
wordfileDoc.Range.Find.Execute(FindText:="{添加日期}", ReplaceWith:=TextBox9.Text)
MyCommand.Connection.Close()
如果C#不支持,先用以前的C++做成控件再用也一样,不知你懂不懂,如果你看过VBA就会理解了
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WinWordTestApp
{
/// <summary>
/// just testing
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button load;
private WinWordControl.WinWordControl winWordControl1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button Restore;
private System.Windows.Forms.Button close;
/// <summary>
/// needed designer variable
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} /// <summary>
/// cleanuup ressources
/// </summary>
protected override void Dispose( bool disposing )
{
// just to be shure!
winWordControl1.CloseControl(); if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
///
/// </summary>
private void InitializeComponent()
{
this.load = new System.Windows.Forms.Button();
this.winWordControl1 = new WinWordControl.WinWordControl();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.button1 = new System.Windows.Forms.Button();
this.Restore = new System.Windows.Forms.Button();
this.close = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// load
//
this.load.Location = new System.Drawing.Point(592, 24);
this.load.Name = "load";
this.load.Size = new System.Drawing.Size(56, 32);
this.load.TabIndex = 1;
this.load.Text = "load";
this.load.Click += new System.EventHandler(this.load_Click);
//
// winWordControl1
//
this.winWordControl1.Dock = System.Windows.Forms.DockStyle.Left;
this.winWordControl1.Name = "winWordControl1";
this.winWordControl1.Size = new System.Drawing.Size(560, 389);
this.winWordControl1.TabIndex = 2;
//
// openFileDialog1
//
this.openFileDialog1.Filter = "WordDateien (*.doc)|*.doc";
//
// button1
//
this.button1.Location = new System.Drawing.Point(592, 152);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 32);
this.button1.TabIndex = 3;
this.button1.Text = "PreActivate";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Restore
//
this.Restore.Location = new System.Drawing.Point(592, 208);
this.Restore.Name = "Restore";
this.Restore.Size = new System.Drawing.Size(56, 32);
this.Restore.TabIndex = 4;
this.Restore.Text = "Restore Word";
this.Restore.Click += new System.EventHandler(this.Restore_Click);
//
// close
//
this.close.Location = new System.Drawing.Point(592, 72);
this.close.Name = "close";
this.close.Size = new System.Drawing.Size(56, 32);
this.close.TabIndex = 5;
this.close.Text = "Close";
this.close.Click += new System.EventHandler(this.close_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(672, 389);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.close,
this.Restore,
this.button1,
this.winWordControl1,
this.load});
this.Name = "Form1";
this.Text = "Form1";
this.Activated += new System.EventHandler(this.OnActivate);
this.ResumeLayout(false); }
#endregion /// <summary>
/// main entry for your Application
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void OnActivate(object sender, System.EventArgs e)
{
} private void load_Click(object sender, System.EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
winWordControl1.LoadDocument(openFileDialog1.FileName);
}
} private void button1_Click(object sender, System.EventArgs e)
{
winWordControl1.PreActivate();
} private void Restore_Click(object sender, System.EventArgs e)
{
winWordControl1.RestoreWord();
} private void close_Click(object sender, System.EventArgs e)
{
winWordControl1.CloseControl();
}
}
}
Interop.Office.dll
Interop.VBIDE.dll
Interop.Word.dll
WinWordControl.dll
好长的代码呀,给点解释吗
说说看