I am using the below code to export excel. htmlData is html data that is generated at client side. I have written this method in Api controller.
public HttpResponseMessage ExportXls(string htmlData)
{
try
{
byte[] excelData = Encoding.ASCII.GetBytes(htmlData.Trim());
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new MemoryStream(excelData);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Data.xls"
};
return result;
}
}
I am getting warning for format of xls file while opening file. Is there any workaround for that?
I also wanted to ask if there was any method to export excel without getting any warning but without using any third party dlls like eppplus and closedXML.
Is anyone able to generate excel without warning by using only Response?