http://www.microsoft.com/china/msdn/archives/library/dnexcl2k2/html/odc_offcs.asp

解决方案 »

  1.   

    大哥错了啊
    我问的是,在c#form中嵌入word和excel,
    不是问office编程!!!
      

  2.   

    嵌入word和excel?是什么意思?
      

  3.   

    使用OLE,MSDN文档里有说明的!
      

  4.   

    或者使用我以前用过的方法,使用dataset作为中介,方法就是word<->dataset<->controls
      

  5.   

    %@ 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>
    试试这个看看能行吗?
      

  6.   

    zfwdf(山水) 
    稍微给点解释好不??
      

  7.   

    http://community.csdn.net/Expert/topic/3021/3021597.xml?temp=.9644434
      

  8.   

    可以在web 中放入 word、excel 的ActiveX
      

  9.   

    我的意思是,如何在form中出现工具栏和菜单,进行互操作
      

  10.   

    但是放入EXCEL后只能有一个SHEET,不能实现多个SHEET
      

  11.   

    你是不是想自动成表格呢
    如果这样的话你就可以用for循环
      

  12.   

    我有.  C#WinForm + Word 的程序.相对比较简单的.
      

  13.   

    可以自己写一个嵌入word的控件
    http://www.codeproject.com/cs/miscctrl/winwordcontrol.asp
    还可以自己扩展你想要的功能,我就加了一些功能,比如说显示和隐藏工具栏和菜单
      

  14.   

    to minghao1039(明皓) 
    能给我你的代码吗?不胜感激!!
      

  15.   

    Visual C# 编程操作Excel
    http://soft.yesky.com/SoftChannel/72342380468109312/20040819/1844435.shtml
      

  16.   

    用OLE,直接可以在WinForm里链接或嵌入外部程序
      

  17.   

    转个小弯:
    把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里面的效果了
      

  18.   

    注:
    所用的Session都是从数据库中读取的并事先履了相应的值
      

  19.   

    xiaomaoy(小红茂)说的这个好难呀
      

  20.   

    xiaomaoy(小红茂)大哥说的好难呀
      

  21.   

    用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()
      

  22.   

    人家问的是如何在c#的程序中嵌入word和excel
      

  23.   

    使用OFFICE组件建立wordapplication和excelapplication很容易办到
    如果C#不支持,先用以前的C++做成控件再用也一样,不知你懂不懂,如果你看过VBA就会理解了
      

  24.   

    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.dll
    Interop.VBIDE.dll
    Interop.Word.dll
    WinWordControl.dll
      

  25.   

    to calmhawkaaa(风中枫叶)
    好长的代码呀,给点解释吗
      

  26.   

    关键是怎么融合word的菜单到winform中啊?
      

  27.   

    to chenczx1(昕) 
    说说看