gridview导excel及解决导出中文乱码的方法
2013-07-12 11:20
447 查看
要全部展示数据,所以导出时要先将翻页取消,重新绑定数据:gridview的allowpaging属性设置为false,然后databind()一下
<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true" CodeFile="SysUser.aspx.cs" Inherits="Autho_SysUser2" %>
添加方法:
public override void VerifyRenderingInServerForm(Control control)
{
}
private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
protected void btnCheck0_Click(object sender, EventArgs e)
{
grdlogin.AllowPaging = false;
if (tbxXingming.Text != "")
{
BllImslog bllimslog = new BllImslog();
grdlogin.DataSource = bllimslog.GetRequestLog(tbxXingming.Text, ddlLoginsitu.SelectedValue, tbxStime.Text, tbxEtime.Text);
grdlogin.DataBind();
}
else
{
BindData();
}
ToExcel(this.grdlogin, System.Web.HttpUtility.UrlEncode("IMS登陆情况报表.xls", System.Text.Encoding.UTF8));
}
<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true" CodeFile="SysUser.aspx.cs" Inherits="Autho_SysUser2" %>
添加方法:
public override void VerifyRenderingInServerForm(Control control)
{
}
private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
protected void btnCheck0_Click(object sender, EventArgs e)
{
grdlogin.AllowPaging = false;
if (tbxXingming.Text != "")
{
BllImslog bllimslog = new BllImslog();
grdlogin.DataSource = bllimslog.GetRequestLog(tbxXingming.Text, ddlLoginsitu.SelectedValue, tbxStime.Text, tbxEtime.Text);
grdlogin.DataBind();
}
else
{
BindData();
}
ToExcel(this.grdlogin, System.Web.HttpUtility.UrlEncode("IMS登陆情况报表.xls", System.Text.Encoding.UTF8));
}
相关文章推荐
- Gridview导出为Excel的时候,中文文件名乱码,解决方法
- Mysql中文乱码以及导出为sql语句和Excel问题解决方法[图文]
- PHP Excel类Spreadsheet_Excel_Writer 导出UTF8中文乱码的解决方法。
- asp.net 导出Excel 在Firefox中中文乱码的解决方法
- asp.net导出Excel显示中文乱码的解决方法
- asp.net导出Excel显示中文乱码的解决方法
- 解决GridView导出Excel后,分页,排序,中文乱码的问题
- Mysql中文乱码以及导出为sql语句和Excel问题解决方法[图文]
- asp.net 导出Excel 在Firefox中中文乱码的解决方法
- asp.net 导出excel 中文乱码解决方法 (转)
- asp.net 导出excel 中文乱码解决方法
- Asp.NET导出Excel文件乱码解决若干方法
- JAVA以UTF-8导出CSV文件,用excel打开产生乱码的解决方法
- 解决导出中文文件名乱码的方法
- python 写csv文件,excel打开中文乱码解决方法
- 导出Excel中文名乱码解决办法
- 解决gridview导出到excel中汉字出现乱码的问题
- [转]mysql导入导出数据中文乱码解决方法小结
- appfuse 中DisplayTag 导出EXCEL,PDF格式中文乱码问题的解决
- 实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法