Exporting data from Grid or DataTable to Excel is so simple.

Source: Internet
Author: User

I used to think that exporting data from a Grid or able to an Excel file is very complicated, and it may be too difficult to use a class library or something.

After reading the FineUI Implementation Method for exporting Grid to Excel, it is actually very simple. It seems that it is very difficult to change one idea.
1. Aspx background code outputs Content Type informationCopy codeThe Code is as follows: Response. ClearContent ();
Response. AddHeader ("content-disposition", "attachment; filename=MyExcelFile.xls ");
Response. ContentType = "application/excel ";
Response. Write (GetGridTableHtml (Grid1 ));
Response. End (); 2. Directly output Html code
Response. Write (@"
<Table border = "1">
<Tr>
<Td> Excel </td>
<Td> By Html </td>
</Tr>
</Table> ")

This implementation is sufficient for simply exporting data to Excel.
Test method: Save the html code as an Excel file to see the effect.

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.