|
发表于 2014-8-11 10:30:57
|
显示全部楼层
飞哥,帮忙看一下为什么在导出excel的时候有时是乱码
public static bool ExportGridViewToSimpleExcel(Control gvExport)
{
try
{
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Export.xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvExport.RenderControl(htw);
HttpContext.Current.Response.Write(sw);
HttpContext.Current.Response.End();
return true;
}
catch
{
return false;
}
} |
|