This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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
  • 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: 5808
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • 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
  • 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: 5808
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • 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
  • 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: 5808
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • 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.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!