在显示页面我通过重定向到打印页面:Server.Transfer("PrintPage.aspx");然后在打印页面中通过ExpertControl(this, DocumentType.Word);方法导出到WORD: 
public void ExpertControl(System.Web.UI.Control source, DocumentType type) { 
//设置Http的头信息,编码格式 
if (type == DocumentType.Excel) 

//Excel 
Response.AppendHeader("Content-Disposition","attachment;filename="+lblProjectName.Text +".xls"); 
Response.ContentType = "application/ms-excel"; 

else if (type == DocumentType.Word) 

//Word if (this.lblPrjBianHao.Text=="") 

Response.AppendHeader("Content-Disposition","attachment;filename="+this.lblProjectName.Text+".doc"); 

else 

Response.AppendHeader("Content-Disposition","attachment;filename="+this.lblPrjBianHao.Text+"."+this.lblProjectName.Text+".doc"); 

Response.ContentType = "application/ms-word"; 

Response.Charset = "utf-8";  
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 
//关闭控件的视图状态 
source.Page.EnableViewState =false;  
//初始化HtmlWriter 
System.IO.StringWriter writer = new System.IO.StringWriter() ; 
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer); 
source.RenderControl(htmlWriter); 
//输出 
Response.Write(writer.ToString()); 
Response.End(); 
} 因为导出的某些WORD文件不只一页,所以要求在页脚自动加上打印日期及第几页/总页数,请知道的人帮帮我,谢谢!

解决方案 »

  1.   

    //添加页眉
     WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
     WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
     WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉信息]");
      

  2.   

    http://www.codeproject.com/KB/office/ms_office_automation.aspx
      

  3.   

    WordApp.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader; 
                WordApp.Selection.InsertAfter(head.ToString()); 
                WordApp.Selection.Font.Size = 30; 我用的此方法 
      

  4.   

    宏录制 
      If ActiveWindow.View.SplitSpecial <> wdPaneNone Then 
            ActiveWindow.Panes(2).Close 
        End If 
        If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ 
            ActivePane.View.Type = wdOutlineView Then 
            ActiveWindow.ActivePane.View.Type = wdPrintView 
        End If 
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 
    '页码 
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage 
        Selection.TypeText Text:="/" 
    '页数 
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages 
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument 
      

  5.   

    用com组件,然后用模板操作
    模板里面设置格式