Export and download the Excel file, but you cannot customize the style!

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.