我的defalut.aspx里有个labe1控件,和datagrid控件,我在网上查了很多都只是把datagrid里的数据导出到word,有没有什么方法可以把datagrid以外的控件,即页面显示的所有信息都导入到word,请高手指教,我下面的程序如何修改
    private void ExportDataGrid(string FileType, string FileName) 
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        datagrid1.RenderControl (hw );
        Response.Write(tw.ToString());
        Response.End();
    }
    protected void BtEord_Click(object sender, EventArgs e)
    {
        ExportDataGrid("application/ms-word", "Word.doc");    }

解决方案 »

  1.   

    private void ExportDataGrid(string FileType, string FileName) 
        { 
                    string filePath = Server.MapPath("DocFiles/" + FileName);
            System.IO.FileStream myFileStream = new System.IO.FileStream
                (filePath, System.IO.FileMode.Create);
            System.IO.TextWriter write = new System.IO.StreamWriter(myFileStream, System.Text.Encoding.GetEncoding("gb2312"));
            write.WriteLine("<html>");
            write.WriteLine("<head>"); 
            write.WriteLine("</head>");
            write.WriteLine("<body>");
            write.WriteLine(lblContent.Text);
            write.WriteLine("</body>");
            write.WriteLine("</html>");
            write.Close();    

      

  2.   

    to:viki117
    您那有没有用word.dll的例子啊
      

  3.   

    我看到有的例子上写
                Word.Application WordApp = new Word.ApplicationClass();
                Word.Document WordDoc = WordApp.Documents.Add(ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing);
    这个word是怎么来的,需要添加什么引用吗?我加了Microsoft.Office.Interop.Word.dll,也没有用阿