asp.net中Table生成Excel表格的方法
更新时间:2015年01月07日 10:05:33 投稿:shichen2014
这篇文章主要介绍了asp.net中Table生成Excel表格的方法,可实现将html的table表格生成excel的功能,需要的朋友可以参考下
本文实例讲述了asp.net中Table生成Excel表格的方法。分享给大家供大家参考。
具体实现方法如下:
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/Css/Balance.css" rel="stylesheet" />
<title></title>
<script runat="server">
protected void writeXls(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel.numberformat:@";
this.EnableViewState = false;
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");//设置输出流为简体中文
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Title + ".xls");
Response.Write(printHid.Value);
Response.End();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="printHid" runat="server" />
<button onclick="getHtmltoValue()" >生成excel</button>
<script type="text/javascript">
function getHtmltoValue() {
document.getElementById("<%=printHid.ClientID%>").value = document.getElementById("printDiv").innerHTML;
}
</script>
<table >
.......
</table>
</form>
</body>
<html>
希望本文所述对大家的asp.net程序设计有所帮助。
相关文章
ASP.NET Core中如何利用多种方式给Action传参
这篇文章主要给大家介绍了关于ASP.NET Core中如何利用多种方式给Action传参的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-12-12
.net core webapi通过中间件获取请求和响应内容的方法
这篇文章主要介绍了.net core webapi通过中间件获取请求和响应内容的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下2019-09-09
ASP.NET State service状态服务的问题解决方法
每次重启机器以后,在.NET2005上跑Web程序老是遇到这样的问题2008-11-11
ASP.NET笔记之 Request 、Response 与Server的使用
本篇文章小编为大家介绍,ASP.NET笔记之 Request 、Response 与Server的使用。需要的朋友参考下2013-04-04


最新评论