现在要做一个报表,要按照word设计的格式,把数据写入word模板,并且还要分页,最好还能把word文件生成PDF文件。
谢谢!

解决方案 »

  1.   

    的调用word的com组件,很容易出错的
      

  2.   

    word 里面有 域这个概念。 楼主可以搞下, 就是在指定的格式下加数据 ,比较简单
      

  3.   

    没用过,生成Excel已经够麻烦的啦.不过可以考虑直接生成PDF,,使用itextsharp
    引用这个Dll插件,再调用相应方法.
      

  4.   

    在word模板里边写好书签,在程序里直接给指定的书签赋值。
      

  5.   

    /// <summary>
      /// 添写WORD文档
      /// </summary>
      /// <param name="dotpath">模板地址</param>
      /// <param name="struseid">资料ID</param>
      public void datoword(string dotpath, string struseid)
      {
      string strsvepath;//储存目录
      object missing = System.Reflection.Missing.Value;
      if (App == null)
      App = new Word.ApplicationClass();
      App.Visible = false;  object oTemplate = dotpath;
      //试过真接输出到PDF打印机。效率更低
      App.ActivePrinter = "MS Publisher Color Printer";
      doc = App.Documents.Add(ref oTemplate, ref missing, ref missing, ref missing);
      doc.Activate();
      doc.ActiveWindow.View.ShowFieldCodes = true;
      Word.Books bms = doc.Books;  //建立D目录
      strsvepath =Server.MapPath(".").ToString() + "\\doc\\"+struseid+"\\";
      if (Directory.Exists(strsvepath))
      {
      }
      else
      {
      Directory.CreateDirectory(strsvepath);
      }
      strsvepath = Server.MapPath(".").ToString() + "\\pdf\\" + struseid + "\\";
      if (Directory.Exists(strsvepath))
      {
      }
      else
      {
      Directory.CreateDirectory(strsvepath);
      }  //添写内容
      inputdata(bms, struseid);
      oTemplate = Server.MapPath(".") + "\\doc\\"+struseid+ "\\" + struseid +".doc";  doc.SaveAs(ref oTemplate, 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);
      App.Quit(ref missing, ref missing, ref missing);
        
        
      }
      

  6.   

    /// <summary>
      /// 将数据添入指定WORD表区域,注意列数量保持和WORD一样不然出错。
      /// </summary>
      /// <param name="wordtab">标签位置表对像</param>
      /// <param name="dts">要添加的数据源</param>
      /// <param name="rowscont">原行数量</param>
      /// <param name="tablehei">行高</param>
      /// <param name="x">开始添加的行</param>
      /// <param name="y">开始添加的列</param>
      private void inputtable(Word.Table wordtab,DataTable dts,float tablehei,int rowscont, int x,int y)
      {
      //Word.Table newTable = bm.Range.Tables[1];
      //bm.Range.Tables[1].Rows.Height;
      //粘贴
      //bm.Range.Paste();
      //添加一行
      if (dts.Rows.Count > 0)
      {
      object ff = 1;
      //得出控制高度
      tablehei = tablehei * rowscont;
      //bm.Application.ActiveWindow.View.ShowFieldCodes = true;
      float rowhei = 0;  if (dts.Rows.Count > rowscont)
      {
      ff = dts.Rows.Count - rowscont;
      App.Selection.InsertRows(ref ff);
      //获得总高度,以保持高度不变
      tablehei = App.Selection.Cells.Height * rowscont;
      rowhei = tablehei / dts.Rows.Count;
      }
      for (int b = 0; b < dts.Columns.Count; b++)
      {
      for (int i = 0; i < dts.Rows.Count; i++)
      {
      if (rowhei != 0)
      {
      wordtab.Cell(i + x, b + y).Height = rowhei;  }
      wordtab.Cell(i + x, b + y).Range.Text = dts.Rows[i][b].ToString();
      }
      }
      }  }
      

  7.   

    错误提示:当前上下文中不存在名称“App”
      

  8.   

    需要引用OFFICE.WORD的。类库。
      

  9.   

    liumj2001
    你的QQ号是多少?我能加你咨询吗?