How to make real xls file on asp.net c #?

I have this code to extract a table to a computer in a .xls file:

// I have a string which contains HTML table codes, named as excelTable

HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Disposition", String.Format("Attachment;Filename=file.xls", ));
response.Buffer = true;
response.ContentEncoding = System.Text.Encoding.Default;
response.ContentType = "application/vnd.ms-excel";
response.Write(excelTable);
response.End();

And I saw that this is not a real .xls file. I can open it in Notepad and see my standard html table codes.

Now I understand that the definition is ContentTypenot enough. So what else can I do to create a clean .xls or .xlsx file? Or should I use Excel libraries like OpenXML, Interop, etc.?

+5
source share
1 answer

Actual XLS / XLSX data must be sent back, i.e. data generated in the library (e.g. EEPlus ) or other suitable source.

/ , Excel ", HTML". HTML XSL/XLSX, Excel.

: (, Excel), / .

, : XLS/XLSX .

+4

All Articles