I hope you will find it original. Sorry!
Public void exceldown (datatable DT, string strfilename) {response. contentencoding = system. text. encoding. getencoding ("gb2312"); response. appendheader ("content-disposition", "attachment; filename =" + strfilename + ". xls "); string colheaders =" ", ls_item =" "; // defines the table object and row object, and initializes the value of datarow with dataset [] myrow = DT. select (); // It can be similar to DT. int I = 0; int Cl = DT. columns. count; // obtain the titles of each column in the data table. The headers are separated by T. The carriage return (I = 0; I <CL; I ++) is added after the last column title) {if (I = (Cl-1) // Add n {colheaders + = DT to the last column. columns [I]. caption. tostring () + "\ n";} else {colheaders + = DT. columns [I]. caption. tostring () + "\ t" ;}} response. write (colheaders); // the data information written to the HTTP output stream // the data processed row by row (datarow row in myrow) {// write the data in the current row to the HTTP output stream, and leave ls_item empty for downstream data (I = 0; I <CL; I ++) {if (I = (Cl-1) // Add n {ls_item + = row [I] to the last column. tostring () + "\ n";} else {ls_item + = row [I]. tostring () + "\ t" ;}} response. write (ls_item); ls_item = "";} string AA = strfilename + ". xls "; string BB = convert. tobase64string (encoding. utf8.getbytes (AA); byte [] cc = convert. frombase64string (bb); string dd = encoding. utf8.getstring (CC); response. end ();}
Export and download the Excel file, but you cannot customize the style!