The example in this article describes how table in ASP.net generates Excel tables. Share to everyone for your reference.
The implementation methods are as follows:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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");/set output stream to Simplified Chinese
Response.appendheader ("Content-disposition", "attachment;filename=" + Title + ". xls");
Response.Write (Printhid.value);
Response.End ();
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<asp:hiddenfield id= "Printhid" runat= "Server"/>
<button onclick= "Gethtmltovalue ()" > Generation excel</button>
<script type= "Text/javascript" >
function Gethtmltovalue () {
document.getElementById ("<%=printHid.ClientID%>"). Value = document.getElementById ("Printdiv"). InnerHTML;
}
</script>
<table >
.......
</table>
</form>
</body>
I hope this article will help you with the ASP.net program design.