I would like to save an html table (preferably as spreadsheet) in some document format. The document should preserve all the styles(color,break,table structure). Currently it is exported as .xls but in the newer versions of office a warning message prompts every time the file is opened "The file format and extension of .xls don't match. The file could be corrupted or unsafe. Unless you trust its source don't open it. Do you want to open it anyway?"
Is there anyway to avoid this warning message ? Is there any other better document format available ?
The code which generates the xls file is:
Response.Clear();
Response.ContentType = "application/vnd.xls";
Response.AddHeader("content-disposition", "attachment; filename=QueryResult.xls");
Response.Write("<html xmlns:x='urn:schemas-microsoft-com:office:excel'>");
Response.Write("<head>");
Response.Write("<meta http-equiv='Content-Type' content='text/html;charset=windows-1252'>");
Response.Write("<!--[if gte mso 9]>");
Response.Write("<xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
Response.Write("<x:Name>sheet1</x:Name>");
Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Panes>");
Response.Write("</x:Panes>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]-->");
Response.Write("</head>");
Response.Write("<body>");
Response.Write("<table>");
System.IO.StringWriter stringWrite1 = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite1 = new HtmlTextWriter(stringWrite1);
ReportGrid.RenderControl(htmlWrite1);
Response.Write(stringWrite1.ToString());
Response.Write("</table>");
Response.Write("</body>");
Response.Write("</html>");
Response.End();