导出EXCEL出现乱码,帮帮忙
使用了网上的方法导出EXCEL:
protected void bt_excel_Click(object sender, EventArgs e)
{
if (gd_data.Rows.Count > 0)
{
//调用导出方法
ExportGridViewForUTF8(gd_data, DateTime.Now.ToShortDateString() + ".xls");
}
else
{
Response.Write("<script language='javascript'>alert('查询的数据为空!')</script>");
}
}
private void ExportGridViewForUTF8(GridView GridView, string filename)
{
string attachment = "attachment; filename=" + filename;
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", attachment);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
但导出的EXCEL出现乱码
给位大侠帮帮忙!!
Excel
.NEt
乱码
------解决方案--------------------换其他编码方式看看
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
------解决方案--------------------乱码肯定就是编码方式问题了 万变不离其中啊