如何将html里的table导出到Excel-CSDN论坛
1个回答
2016-05-12 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
<input type="button" value="导出" style="width: 50px;" onclick="getExcel();" />
function getExcel() {
var tabHtml = $("#tb_Class").html();
$.post("../Ajax/GetExcel", { tab: encodeURIComponent(tabHtml) });
}
Controler中:
public void GetExcel()
{
string sHtml = Server.UrlDecode(Request.Form["tab"]);
ExportToExcel("application/ms-excel", "XXXXX表.xls", sHtml.ToString());
}
public void ExportToExcel(string FileType, string FileName, string ExcelContent)
{
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
StringWriter tw = new StringWriter();
Response.Output.Write(ExcelContent.ToString());
Response.Flush();
Response.End();
}
function getExcel() {
var tabHtml = $("#tb_Class").html();
$.post("../Ajax/GetExcel", { tab: encodeURIComponent(tabHtml) });
}
Controler中:
public void GetExcel()
{
string sHtml = Server.UrlDecode(Request.Form["tab"]);
ExportToExcel("application/ms-excel", "XXXXX表.xls", sHtml.ToString());
}
public void ExportToExcel(string FileType, string FileName, string ExcelContent)
{
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
StringWriter tw = new StringWriter();
Response.Output.Write(ExcelContent.ToString());
Response.Flush();
Response.End();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询