怎样将数据库中的数据保存到客户端的word文档中?

解决方案 »

  1.   

    我原来做过一个公文的处理的问题,解决过这个问题,下面给你看我的代码这样做后,就可以实现你的功能了...
    try
    {
    object Nothing=System.Reflection.Missing.Value;//调用默认参数
    //取得Word文件保存路径
    object [email protected];
    Word.Application WordApp=new Word.ApplicationClass();
    object missing = System.Reflection.Missing.Value;
    Word.Document WordDoc=WordApp.Documents.Add(ref missing,ref missing,ref missing,ref missing);
    //增加一表格
    Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,1,1,ref Nothing,ref Nothing);
    //在表格第一单元格中添加自定义的文字内容
    table.Cell(1,1).Range.Text=tbBody.Text;
    WordDoc.Paragraphs.Last.Range.Text="欢迎参加学习!";
    //将WordDoc文档对象的内容保存为DOC文档
    WordDoc.SaveAs(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
    WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
    WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
    lbResult.Text="文档路径:<a href='"+tbPath.Text+"'>"+tbPath.Text+"</a>(点击链接查看)<br>生成结果:成功!";
      

  2.   

    谢谢bcwchina(修哲)兄的回复,有些东西还是看不懂,能不能单独交流一下?qq 357037268
      

  3.   

    1.将数据输出到客户端(用xml或者hidden保存),javascript操作VBA生成WordApplication对象,往里面写数据。此时,客户端必须在可信站点,并且降低运行ActiveX的权限。
    2.用C#在服务器端引用word生成WordApplication,往里面写数据。此时服务器要装word
    3.用C#在服务器端生成html文件,然后,动态输出该文件,注意把该文件输出的Content-Type改为word,这样,传到客户端后自动调用word打开,而word能打开html格式,满足需求
    4.如果数据已经显示在客户端,可以用javascript生成WordApplication,然后将数据复制到剪切板,并粘贴到WORD里。