C# asp.net 把GridView資料 匯出到 Excel
1 Response.Clear();
2 Response.Buffer = true;
3 Response.Charset = "GB2312";
4 Response.AppendHeader("Content-Disposition", "attachment;filename=jtkc.xls");
5 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//設定輸出流為簡體中文
6 Response.ContentType = "application/ms-excel";//設定輸出檔案型別為excel檔案。
7 this.EnableViewState = false;
8 System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
9 System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
10 System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
11 grvExcel.RenderControl(oHtmlTextWriter);
12 Response.Write(oStringWriter.ToString());
13 Response.End();
2 Response.Buffer = true;
3 Response.Charset = "GB2312";
4 Response.AppendHeader("Content-Disposition", "attachment;filename=jtkc.xls");
5 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//設定輸出流為簡體中文
6 Response.ContentType = "application/ms-excel";//設定輸出檔案型別為excel檔案。
7 this.EnableViewState = false;
8 System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
9 System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
10 System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
11 grvExcel.RenderControl(oHtmlTextWriter);
12 Response.Write(oStringWriter.ToString());
13 Response.End();
1.這過程中遇到一些問題,剛開始是提示GridView必須放在runat="server"的窗體中,但是
只需要重寫VerifyRenderingInServerForm方法,將內容清空就可以了。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> public override void VerifyRenderingInServerForm(Control control)
{
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> public override void VerifyRenderingInServerForm(Control control)
{
}
2。第二個問題是提示:只能在 Render(); 期間呼叫 RegisterForEventValidation
這個問題比較好解決,只需要在前臺頁面的@Page指令中加上一個屬性:EnableEventValidation="false"
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-566599/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 將資料匯出到ExcelExcel
- C# 從datagridview中匯出到excelC#ViewExcel
- hive匯出到csv hive匯出到excelHiveExcel
- asp.net中GridView匯出資料ASP.NETView
- java 匯出到EXCELJavaExcel
- 用php把資料匯出excelPHPExcel
- ORACLE資料匯出到Excel、txt、HTML實用方法OracleExcelHTML
- 用SQL Loader將Excel資料匯出到OracleSQLExcelOracle
- 將MYSQL中資料匯出到EXCEL表MySqlExcel
- 匯出到Excel的操作Excel
- 資料庫文件編寫,如何通過Navicat把表導成表格?資料庫快速匯出為excel表格資訊,excel匯出到word表格資料庫Excel
- 用GridView匯入匯出Excel,並列印GridViewViewExcel
- 把Excel表資料匯入到mysqlExcelMySql
- ASP.NET 2.0匯出到Excel時保留換行的方法ASP.NETExcel
- GridView匯入至EXCELViewExcel
- ASP.NET EXCEL資料的匯出和匯入ASP.NETExcel
- DevExpress GridView匯入匯出ExceldevExpressViewExcel
- 轉載:利用SQL*Loader將 Excel 資料匯出到資料庫中SQLExcel資料庫
- 通過GridView匯出ExcelViewExcel
- MSSQL資料匯出到MYSQLMySql
- json陣列匯出到ExcelJSON陣列Excel
- 表結構匯出到excel中Excel
- fastadmin的匯出到excel功能ASTExcel
- 大文字資料,匯入匯出到資料庫資料庫
- Dynamics CRM 資料匯出到Excel時列標題不能重複Excel
- 第四節:海量資料匯出到Excel、百萬Excel匯入到DB、秒級/分鐘級排行版Excel
- Vue+element ui table 匯出到excelVueUIExcel
- DataGrid 匯出到 Excel 的幫助類Excel
- asp.net 操作Excel表資料匯入到SQL Server資料庫ASP.NETExcelSQLServer資料庫
- C#匯入EXCELC#Excel
- Asp.net 匯出ExcelASP.NETExcel
- banq您好,請問如何把excel的資料匯入mysql.ExcelMySql
- 將dataGridView內容匯出到Excel檔案ViewExcel
- 如何將資料熱匯出到檔案
- 從hive將資料匯出到mysql(轉)HiveMySql
- ASP.NET 匯出gridview中的資料到Excel表中,並對指定單元格換行操作ASP.NETViewExcel
- ASP.NET Excel匯入和匯出ASP.NETExcel
- asp.net Excel匯出方法ASP.NETExcel