0

C# dataTable/Html to xls When export and then opened by Excel and using the save and send as attachments the file format changes to xlsb how to prevent this?

My code is similar to the working exemple in this links

Export HTML Table to Excel using ASP.NET

My code Similar to that system of doing that

    string contentType = "application/excel";
    Response.ContentType = I tried different types;
    Response.AddHeader("Content-Disposition", "attachment; filename=myFile.xls );
    Response.Write(stringData);
    Response.Flush();
    Response.End();

The file exported as xls but when I open it and select save and send as attachments to Outlook it transform to xlsb

I actually somehow changed it to export as xlsx with different content type but the code was not saved and I don't remember how It was made and now as xlsx it tell me that the file currept and won't able to open

I don't want to use Microsoft Office library or other library's

I Want it to stay xls or to able to open as xlsx

Community
  • 1
  • 1
Mozy
  • 1

1 Answers1

0

I don't want to rewrite the code which people already have. The following two links will be helpful.

http://mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm (Free license)

http://techbrij.com/export-excel-xls-xlsx-asp-net-npoi-epplus

https://social.msdn.microsoft.com/Forums/vstudio/en-US/0b3b9dd0-8aab-4677-ac29-f6f63a07453c/export-dataset-to-excel-xlsx?forum=csharpgeneral

Also check if different Content-Type can fix the issue. Try the following first.

application/vnd.ms-excel