gridview 导出到excel,repeater类似
?protected void Convert2Excel(string fileName)
??? {
??????? //設定輸入文件流的字符集
??????? this.Response.Charset = "gb2312";
??????? //設定編碼方式為UTF7
??????? this.Response.ContentEncoding = Encoding.UTF7;
??????? //設定響應頭 即響應中含有附件
??????? this.Response.AppendHeader("Content-Disposition",
??????????? string.Format("attachments;filename={0}",
??????????? HttpUtility.UrlEncode(fileName,Encoding.UTF8).ToString())
??????????? );
??????? //設定響應類型為Excel文件
??????? this.Response.ContentType = "application/ms-excel";
??????? //響應不存儲于ViewState中
??????? this.EnableViewState = false;
??????? //實例化字符流寫入器
??????? StringWriter writer = new StringWriter();
??????? //實例化Html字符流寫入器
??????? HtmlTextWriter hw = new HtmlTextWriter(writer);
??????? //將GridView中所有的數據和格式轉化為Html代碼并寫入至Html字符流寫入器
??????? this.GridView1.RenderControl(hw);
??????? //在響應中輸出GridView控件的Html代碼
??????? this.Response.Write(writer.ToString());
??????? //停止響應
??????? this.Response.End();
??? }
??? protected void btnConvert2Excel_Click(object sender, EventArgs e)
??? {
??????? //輸入文件名?? 導入至Excel文件中
??????? this.Convert2Excel("員工信息.xls");
??? }
總結
以上是生活随笔為你收集整理的gridview 导出到excel,repeater类似的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 飞鸽传书 参与了公司的程序设计比赛
- 下一篇: 【源码】2012年斗地主算法大全