The main idea is to export the document through the GridView.
create a new ASPX page, the page creates a GridView control, and the background binds the data source.
Then print directly in load to exportThe 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:boundfield datafield="Name"headertext="name"/> <asp:boundfield datafield="Sex"headertext="Sex"/> <asp:boundfield datafield="BirthDay"headertext="Date of birth"/> <asp:boundfield datafield="StudentID"headertext="ID Number"/> <asp:boundfield datafield="Jieduid"headertext="borrow took card number"/> <asp:boundfield datafield="familymemberinfo_name1"headertext="First Guardian name"/> </Columns> "Azure"Font-size="12px"horizontalalign="Center"/> <rowstyle horizontalalign="Center"/> <pagerstyle horizontalalign="Center"/> </asp:GridView>
Background:
/// <summary> ///define functions to export Excel/// </summary> /// <param name= "FileType" ></param> /// <param name= "FileName" ></param> Private voidExport (stringFileType,stringFileName) { for(inti =0; i < GridView1.Rows.Count; i++) { //This gives the specified column edit format, the digital output as text, to prevent the digital overflowGridview1.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=NewStringWriter (); HtmlTextWriter HW=NewHtmlTextWriter (TW); Gridview1.rendercontrol (HW); Response.Write (TW. ToString ()); Response.End (); } /// <summary> ///This method must be overridden, or an error will occur/// </summary> /// <param name= "Control" ></param> Public Override voidVerifyrenderinginserverform (Control control) {}