I'm working on a page that exports an HTML table to an Excel spreadsheet by using the markup listed below to create the spreadsheet. However, whenever a new Excel document starts, I get a warning that "ExcelDocName.xls's file format and extension don't match. The file might be dangerous or corrupt." Excel cannot open the file "ExcelDocName.xlsx" because the file format or file extension is invalid, despite the fact that I assume this is happening due of the.xls extension. How should I change this markup to fix these problems?
<!DOCTYPE html><html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>
<head>
<meta http-equiv=Content-Type content='text/html;charset=windows-1252'><meta name=Generator content='Microsoft Excel 11'>
<meta name=ProgId content=Excel.Sheet> <meta name=Generator content='Microsoft Excel 11'>
<style>
<!--table @page{}-->
</style>
<!--[if gte mso 9]><xml> <x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet> <x:Name>Sheet1</x:Name> <x:WorksheetOptions><x:Panes>
</x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets><x:ExcelWorkbook></xml><![endif]-->
</head>
<body><form method='POST' action='" &APSPostName&".asp' name='frmExcel'></form>
<!-- Table HTML goes here -->
</body></html>
The following is included after the markup is created.
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename="&ExcelName&".xls"