Introduce DL first. Org. in2bits. myxls. dll
: Http://download.csdn.net/detail/tesky0125/5300853
On the page, click "Export". The event C # code is as follows:
# Region export Excel button event protected void exportexcelstaff1click (Object sender, eventargs e) {try {Org. in2bits. myxls. xlsdocument TZ = new Org. in2bits. myxls. xlsdocument (); tz. filename = datetime. now. tostring (). replace ("-",""). replace (":",""). replace ("", "") + ". xls "; // Excel file name Org. in2bits. myxls. worksheet sheet = tz. workbook. worksheets. addnamed ("sheet1"); // Excel worksheet name Org. in2bits. myxls. cells = sheet. cells; int colnum = gridview_data.columns.count; // obtain the number of columns in the gridview for (INT I = 0; I <colnum; I ++) {cells. addvaluecell (1, (I + 1), gridview_data.columns [I]. headertext); // export the gridview column name} For (INT I = 0; I <gridview_data.rows.count; I ++) {for (Int J = 0; j <colnum; j ++) {cells. addvaluecell (I + 2), (J + 1), gridview_data.rows [I]. cells [J]. text. trim ());}}//Tz. save (@ "D: \"); // save it to the specified position tz. send (); // output the prepared Excel file to the client} catch {}}# endregion export Excel button event