导出EXCEL2003
??????? public void OutPutExcel(string filename)
??????? {
??????????? //定義文檔類型、字符編碼
??????????? Response.Clear();
??????????? Response.Buffer = true;
??????????? Response.Charset = "UTF-8";
??????????? //下面這行很重要, attachment 參數表示作為附件下載,您可以改成 online在線打開
??????????? //filename=FileFlow.xls 指定輸出文件的名稱,注意其擴展名和指定文件類型相符,可以為:.doc .xls .txt .htm
??????????? Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
??????????? Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
??????????? //Response.ContentType指定文件類型 可以為application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他瀏覽器可直接支持文檔
??????????? Response.ContentType = "application/ms-excel";
??????????? this.EnableViewState = false;
??????????? // 定義一個輸入流
??????????? System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
??????????? System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
??????????? this.GridView1.RenderControl(oHtmlTextWriter);
??????????? //this.RenderControl(oHtmlTextWriter);
??????????? //this 表示輸出本頁,你也可以綁定datagrid,或其他支持obj.RenderControl()屬性的控件
??????????? Response.Write(oStringWriter.ToString());
??????????? Response.End();
??????? }
??????? public override void VerifyRenderingInServerForm(Control control)
??????? {
??????????? // Confirms that an HtmlForm control is rendered for
??????? }
轉載于:https://www.cnblogs.com/VirtualLive/archive/2009/10/13/1582593.html
總結
以上是生活随笔為你收集整理的导出EXCEL2003的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DataFormatString格式化字
- 下一篇: 用《叩响C#之门》复习C#基础知识 第八