DataGrid使用最佳实践(导出excel)
来源:互联网 发布:数据分析算法 编辑:程序博客网 时间:2024/05/18 03:07
导出excel问题:
朋友们在导出时,可能也会遇到乱码的问题,松子儿的解决方法如下:
下面是一段正确的导出按钮事件代码
private void btnMIME_Click(object sender, System.EventArgs e)
...{
Response.ContentType = "application/vnd.ms-excel";//响应类型
Response.Charset = "";//响应编码类型
Response.ContentEncoding = Encoding.UTF7;//注意:UTF8是不支持简体中文的
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
int nCur = dgShow.CurrentPageIndex;
int nSize = dgShow.PageSize;
dgShow.AllowPaging = false;
BindData();
dgShow.Columns[7].Visible =false;
dgShow.RenderControl(hw);
dgShow.Columns[7].Visible =true;
//以下恢复分页
dgShow.AllowPaging = true;
dgShow.CurrentPageIndex = nCur;
dgShow.PageSize = nSize;
BindData();
Response.Write(sw.ToString());
Response.End();
}
注意:设置输出流的http字符集(Response.ContentEncoding),“urf8”:不支持简体中文;“gb2312”:excel不支持,会报错!
- DataGrid使用最佳实践(导出excel)
- ASP.NET应用-DataGrid使用最佳实践
- DataGrid使用----导出到Excel数据表
- DataGrid导出为Excel
- DataGrid导出Excel解决方案
- DataGrid - 导出Excel文件
- DataGrid导出Excel
- DataGrid - 导出Excel文件
- 从datagrid导出Excel
- DataGrid导出Excel(c#)
- DataGrid导出Excel
- DataGrid导出Excel解决方案
- DataGrid、DataSet导出Excel
- DataGrid导出Excel
- dataGrid导出Excel
- DataGrid导出到Excel
- datagrid导出excel
- datagrid导出excel
- 三十种Linux发行版的名称含义
- Etymology of A Linux Distro
- jsf 标签中的action属性与 bankiingbean中的 getXXX()的使用
- 使用 distcc 缩短编译时间
- 让.net程序脱离.NET Framework在Linux下运行
- DataGrid使用最佳实践(导出excel)
- (感人)有一种爱叫放手
- C#开源资源
- GPRS电力系统远程抄表系统解决方案
- GPRS电力系统远程抄表系统解决方案
- php 5.2.x 研究:require 和 include 的不同
- 一次经典的电话会议
- Dll
- fedora 6安装注意事项