0

My Excel file generated by the table2excel jQuery plugin will not open properly, and will throw XXXX.xls file format; the extension doesn't match. and I think this file is a text file, not a real binary excel file. error

Js:

e.uri = "data:application/vnd.ms-excel;base64,";
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
a = document.createElement("a");
a.download = getFileName(e.settings);
a.href = link;

document.body.appendChild(a);

a.click();

document.body.removeChild(a);

Visit my jsfiddle to see my code!

feng xu
  • 13
  • 5
  • Possible duplicate of [Excel file generated by table2excel jQuery plugin throws error when opened](http://stackoverflow.com/questions/33031702/excel-file-generated-by-table2excel-jquery-plugin-throws-error-when-opened) – David Archibald Sep 27 '16 at 04:57
  • https://stackoverflow.com/a/50819212/414744 This might help – Ravi Ranjan Oct 31 '18 at 11:51

1 Answers1

0

I happened across this SO question, and it appears you are using the answer's jsfiddle. The reason it pops up the warning is because it is formated in .xlsx and has an extension of .xls, so it thinks it could be a virus. To solve this all you have to do is use the other jsfiddle, and have a version of Excel above 2007, as the other jsfiddle doesn't convert the file format, and Excel above 2007 can open those files.

Community
  • 1
  • 1
David Archibald
  • 1,431
  • 14
  • 27
  • Thanks for answering, I used the excel2016, when I used your method, there will be the following error: excel cannot open the file xxx.xlsx' because the file format is not valid error – feng xu Sep 27 '16 at 05:34
  • I answered because I thought you were using a different version, but it works just fine for me if I click yes in 2010. – David Archibald Sep 27 '16 at 23:11
  • Anyway, thank you,I have resolved that my previous solution is not appropriate, because he is the text format forced into a .xls or .xlsx suffix, and excel is binary – feng xu Sep 28 '16 at 02:59
  • Sorry I don't get what you mean, did I help or not? Probably best to not have too many comments, but I need the clarification. – David Archibald Sep 28 '16 at 04:25
  • In simple terms, the table2excel jQuery plugin can not be used to get a real excel file.This file is not a real binary file.I'm sorry for my bad English. – feng xu Sep 28 '16 at 05:22