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
• 38,000 points
1,657 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
• 63,600 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
• 23,260 points
7,972 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,690 points
1,086 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: ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 63,600 points
650 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
• 63,600 points
863 views
0 votes
0 answers
0 votes
1 answer

Excel viewer lib

You will need to save your excel ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 63,600 points
507 views
0 votes
1 answer

Remove the Rupee symbol in Laravel

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

answered Jan 6, 2023 in Others by narikkadan
• 63,600 points
1,566 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, 2023 in Others by narikkadan
• 63,600 points
916 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
• 63,600 points
769 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
• 63,600 points
2,296 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