首页 > Web开发 > 详细

excel文件使用html导出

时间:2018-09-15 14:26:41      阅读:172      评论:0      收藏:0      [点我收藏+]

<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();

}

excel文件使用html导出

原文:https://www.cnblogs.com/liwp/p/9650775.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!