在asp.net里我想在点击一个BUTTON时,把数据库里的一条数据的某几个字段给搞到word中去,该怎么做呀
小弟我想了好久没有想明白,一点思路都没有,求助各位了!!!!!!!

解决方案 »

  1.   

    http://msdn.microsoft.com/office/understanding/word/codesamples/default.aspx?pull=/library/en-us/odc_wd2003_ta/html/OfficeWordAutomatingTablesData.asp
      

  2.   

    我自己写的一个类~你看看
    public bool ExportWord( DataTable Table)
    {
    object Missing = System.Reflection.Missing.Value;
    int NumRows, NumColumns, rowIndex, colIndex;
    //±£´æwordÎļþµÄ·¾¶
    object FileName = this.strDestinationFilePath;
    Word.ApplicationClass wordApp = new Word.ApplicationClass();
    Word.Document myDoc;
    Word.Table oTable;
    rowIndex = 1;
    colIndex = 0;
    try
    {
    wordApp.Documents.Add(ref Missing,ref Missing,ref Missing, ref Missing);
    myDoc = wordApp.ActiveDocument;
    oTable = myDoc.Tables.Add(myDoc.Range(ref Missing, ref Missing),NumRows=Table.Rows.Count + 1, NumColumns=Table.Columns.Count,ref Missing,ref Missing); //½«ËùµÃµ½µÄ±íµÄÁÐÃû,¸³Öµ¸øµ¥Ôª¸ñ
    foreach(DataColumn Col in Table.Columns)
    {
    colIndex = colIndex + 1;
    oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName);
    } //µÃµ½µÄ±íËùÓÐÐÐ,¸³Öµ¸øµ¥Ôª¸ñ
    foreach(DataRow Row in Table.Rows)
    {
    rowIndex = rowIndex + 1;
    colIndex = 0;
    foreach(DataColumn Col in Table.Columns)
    {
    colIndex = colIndex + 1;
    oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row[Col.ColumnName].ToString());
    }
    } oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleDashDot;
    oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleDot;
    //true:wordÎļþÏÔʾ false:wordÎļþ²»ÏÔʾ
    wordApp.Visible = false;

    myDoc.SaveAs(ref FileName,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing,ref Missing);
    return true;
    }
    catch
    {
    return false;
    }
    finally
    {
    wordApp.Quit( ref Missing,ref Missing, ref Missing );
    } }
      

  3.   

    powerllr(笨笨的招财鸡)
    刚才那篇帖子就是我发的,麻烦再问你一下,当我把数据搞到word中去了后,里面有个表格,怎么样才能把word中的那个表格去掉
    还有我下在数据导入成功后提供下载个打开的功能没,该怎么做解决了这分都是你的了,哈哈
      

  4.   

    powerllr(笨笨的招财鸡)
    他在要挟你哟!
      

  5.   

    怎么样才能把word中的那个表格去掉
    请看http://61.186.252.131/Expert/topic/903/903407.xml?temp=.7777674还有我下在数据导入成功后提供下载个打开的功能没,该怎么做
    你知道那个Word文档路径吗? 搞个linkButton之类的。把地址属性设置成Word文档路径就KO