excel文件使用html导出

<table><tr><td>1</td></tr><tr><td>2</td></tr><tr><td>3</td></tr><tr><td>04</td></tr></table>

 

protected void btnExportExcel_Click(object sender, EventArgs e)
{
ExportExcel("MemberBonusRollingReport.xls", gvMemberTimeReport);


}

 

private void ExportExcel(string as_FileName, GridView gvCurrent)
{

Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" +
HttpUtility.UrlEncode(as_FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = "application/ms-excel";
string strStyle = "<style>td{mso-number-format:\"\\@\";}</style>";
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
this.EnableViewState = false;
//string strStyle = "<style>td{mso-number-format:\"\\@\";}</style>";
StringWriter tw = new StringWriter();
tw.WriteLine(strStyle);
HtmlTextWriter hw = new HtmlTextWriter(tw);
gvCurrent.Page.EnableViewState = false;
tw.WriteLine(strStyle);
gvCurrent.RenderControl(hw);
Response.Write(tw.ToString());
Response.Write("</body></html>");
Response.End();

}

posted @ 2018-09-15 13:50  李文平  阅读(641)  评论(0编辑  收藏  举报