Exporting HTML Table to Excel Extension Issues

0 votes

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"
Nov 14, 2022 in Others by Kithuzzz
• 28,700 points
158 views

1 answer to this question.

0 votes

In my application, I'm experiencing a similar issue. I've just discovered that this is a problem with Microsoft Excel, not the file itself. Starting with Excel 2007 and up to the most recent version of Excel 2016, you cannot open HTML material using Excel unless it has been saved with the.html extension.

Although you can open the file without any issues with Open Office or Libre Office if you save it with the.xls extension, Microsoft Excel will give you errors when you try to open it (2007 - Current)

Solution:

  1. Save the file as a .html extension and inform the user to open it with Microsoft Excel (Once opened they can save it as an excel document).
  2. Save the file with a .xls extension and inform the user to open it with Open Office or Libre Office. to avoid the annoying error.
  3. Save the file with a .xls extension and inform the user about the error and inform them to ignore the error and click yes when it pops up.
answered Nov 14, 2022 by narikkadan
• 53,160 points

Related Questions In Others

0 votes
1 answer

How to import data from a HTML table on a website to excel?

Hello  To import any HTML file in excel there ...READ MORE

answered Feb 10, 2022 in Others by gaurav
• 22,940 points
528 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,630 points
294 views
0 votes
1 answer

Display a table (in the html/Excel spreadsheet meaning) in a iOS app in Swift

Here is the answer to your question: How ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 53,160 points
101 views
0 votes
1 answer

Pivot Chart Table in Excel To Calculate the Count and Display the Chart

It should look something like this: READ MORE

answered Nov 6, 2022 in Others by narikkadan
• 53,160 points
87 views
0 votes
0 answers
0 votes
1 answer

Excel viewer lib

 Try http://viewerjs.org. You will need to save your ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 53,160 points
91 views
0 votes
1 answer

Remove the Rupee symbol in Laravel

Although there are other approaches you may ...READ MORE

answered Jan 6 in Others by narikkadan
• 53,160 points
99 views
0 votes
1 answer

Using createobject("Excel.application") to create excel 2007 application

Try the next adapted way. No need ...READ MORE

answered Jan 13 in Others by narikkadan
• 53,160 points
37 views
0 votes
1 answer

Export HTML Table to Excel- Doesn't Open in Office 2010

We had the same issue too many ...READ MORE

answered Oct 21, 2022 in Others by narikkadan
• 53,160 points
151 views
0 votes
1 answer

Convert table in a jpg image to excel using python

I believe you must execute OCR (optical ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 53,160 points
543 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP