Ive got task to write code to export html table with headers to excel.
What I came up with is serverSide code like this:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=myexcel.xls");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
tbPanel.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
It works quite well but there are some utf-8 characters (russian language) which arent displayed correclty in excel file.
Any ideas that can I do about it ?
Thanks for help
Change your code to the following:
Edit
While I was posting my answer, I saw that you already figured out the same solution. The error message that you’re seeing is explained here: Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site and, unfortunately, there is no way to workaround it.
From the post: