Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Html to excel file generation gives error file format and extension don't match. How to correct

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

While downloading html table as excel sheet I am getting the following error. "The file format and extension "abc.xls" don't match.The file could be corrupted or unsafe.Unless you trust the source don't open it. Do you want to open it anyway?" How to get rid of this message?

Regards,
Rekha
 
Saloon Keeper
Posts: 7185
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTML is not an Excel sheet - you can't save the former with the file extension of the latter and expect thing to work. Let's take a step back: how exactly are you trying to make this work?
 
Rekha Pai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am creating a Blob and setting the type as ms-excel. This gives the error but if I click yes it neatly opens the table in excel sheet.

Regards,
Rekha
 
Tim Moores
Saloon Keeper
Posts: 7185
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the relationship between

I am creating a Blob and setting the type as ms-excel.


and

Html to excel file generation


? How is a blob (which is a database concept) related to HTML (or Excel, for that matter)?

it neatly opens the table in excel sheet.


So the problem is solved now?
 
Rekha Pai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am creating the Blob in javascript. The problem is not solved. I want to get rid of the message "the file format don't match....".

var exceldata = new Blob([tab_text], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" });
var link = document.createElement('a'); //create link download file
link.href = window.URL.createObjectURL(exceldata); // set url for link download
link.setAttribute('download', fileName); //set attribute for link created
document.body.appendChild(link);
link.click();
document.body.removeChild(link);

This is downloading the file. But When I open it in excel it shows the error message.

Regards,
Rekha
 
Tim Moores
Saloon Keeper
Posts: 7185
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure it can be avoided. You're creating an HTML file, but treat it as if it were an Excel file - the behavior you describe follows naturally from that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic