Article 3 C # convert HTML into Excel directly,

Source: Internet
Author: User

Article 3 C # convert HTML into Excel directly,

When writing a project the other day, the customer asked to display the information in an HTML table, and then export the information in Excel. If you want to perform operations in the background, it is estimated that the process is dead. However, after careful consideration, Excel can be published as HTML, which can be converted from HTML to Excel. After several searches, the problem is solved by the code below (Ajax cannot be called because Ajax will not refresh the page ):


Response. contentType = "application/force-download"; Response. addHeader ("content-disposition", "attachment; filename =" + DateTime. now. toString ("yyyyMMddHHmmss") + ". xls "); Response. write ("

The Style and specification of the page can be fully displayed after testing:

Foreground HTML:


The downloaded Excel file:



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.