將ASP.net中的Table中的數(shù)據(jù)導(dǎo)入到Execl
發(fā)表時(shí)間:2024-02-16 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]//定義文檔類型、字符編碼 Response.Clear(); Response.Buffer= true; Response.Charset="GB2312"; //下面這行很重要, attachment 參數(shù)...
//定義文檔類型、字符編碼
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
//下面這行很重要, attachment 參數(shù)表示作為附件下載,您可以改成 online在線打開(kāi)
//filename=FileFlow.xls 指定輸出文件的名稱,注意其擴(kuò)展名和指定文件類型相符,可以為:.doc .xls .txt .htm
Response.AppendHeader("Content-Disposition","attachment;filename=FileFlow.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
//Response.ContentType指定文件類型 可以為application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他瀏覽器可直接支持文檔
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
// 定義一個(gè)輸入流
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.Table_Report.RenderControl(oHtmlTextWriter);
//this 表示輸出本頁(yè),你也可以綁定datagrid,或其他支持obj.RenderControl()屬性的控件
Response.Write(oStringWriter.ToString());
Response.End();