The main idea is to export the document through the GridView. Create a new ASPX page, the page creates the GridView control, and the background binds the data source.
Then print directly in load to export
The GridView at the front desk
<asp:gridview id= "GridView1" bordercolor= "Black" runat= "server" autogeneratecolumns= "False" font-size = "12px" width= "656px" allowsorting= "True" height= "172px" > <Columns> <asp:boundfiel
D datafield= "name" headertext= "name"/> <asp:boundfield datafield= "Sex" headertext= "gender"/> <asp:boundfield datafield= "Birthday" headertext= "date of birth"/> <asp:boundfield "datafield="
Entid "headertext="/> <asp:boundfield datafield= "Jieduid" headertext= "borrow took"/>
<asp:boundfield datafield= "familymemberinfo_name1" headertext= "first Guardian name"/> </Columns>
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/
Background:
<summary>///define functions to export Excel///</summary>///<param name= "FileType" ></p aram>///<param name= "FileName" ></param> private void Export (String FileType, String filen AME) {for (int i = 0; i < GridView1.Rows.Count; i++) {//here gives the specified column an edit format that will Digital output is text, preventing digital overflow gridview1.rows[i]. CELLS[3].
Attributes.Add ("Style", "vnd.ms-excel.numberformat:@");
} Response.Charset = "GB2312";
response.contentencoding = System.Text.Encoding.UTF8;
response.contentencoding = System.Text.Encoding.GetEncoding ("gb2312"); Response.appendheader ("Content-disposition", "attachment;filename=" + httputility.urlencode (filename, Encoding.UTF8).
ToString ());
Response.ContentType = FileType; This.
EnableViewState = false;
StringWriter tw = new StringWriter (); HtmlTextWriter HW = new HtmlTextWriter (TW);
Gridview1.rendercontrol (HW); Response.Write (TW.
ToString ());
Response.End (); ///<summary>///This method must be overridden, otherwise error///</summary>///<param name= "contr Ol ' ></param> public override void Verifyrenderinginserverform (Control control) {}
Author: Angry Trycatch
Source: http://www.cnblogs.com/likeli/