Asp. nettable
This document describes how to generate an Excel Table in asp.net. Share it with you for your reference.
The specific implementation method is as follows:
Copy codeThe Code is as follows:
<! 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"); // set the output stream to simplified Chinese
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 ()"> Generate an excel file </button>
<Script type = "text/javascript">
Function getHtmltoValue (){
Document. getElementById ("<% = printHid. ClientID %>"). value = document. getElementById ("printDiv"). innerHTML;
}
</Script>
<Table>
.......
</Table>
</Form>
</Body>
<Html>
I hope this article will help you design your asp.net program.