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: