下载XLSX损坏 [英] Download XLSX getting corrupted
问题描述
我正在尝试将HTML表转换为AngularJS甚至是纯JavaScript的XLSX.
I'm trying to convert a HTML table to XLSX uisng AngularJS or even plain JavaScript.
当我使用下面的下载格式转换为XLS并打开XLS文件时.
When I'm converting to XLS using below its downloading fine and a XLS file is opening.
var blob = new Blob([template], {type: "data:application/vnd.ms-excel"});
window.navigator.msSaveOrOpenBlob(blob, "myExcel.xls");
但是,我的要求是要使用XLSX中的文件,所以我用如下相同的代码更改了MIME类型和文件扩展名,
But, my requirement wants the file in XLSX, so I changed the MIME type and extension of file in the same code like below,
var blob = new Blob([template], {type: "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
window.navigator.msSaveOrOpenBlob(blob, "myExcel.xlsx");
但是,当我打开下载的xlsx文件时,它已损坏并且MS Office正在弹出错误弹出窗口.
But when I'm opening the downloaded xlsx file its corrupted and MS office is trowing error popup.
我做错了什么以及如何将HTML表转换为 XLSX ? 甚至其他想法也被接受.
What I'm doing wrong and how I can convert a HTML table to XLSX? Even alternate ideas also accepted.
PS:该表非常复杂,行在所有列之内,因此ALASQL,JS-XLSX之类的插件无济于事.
PS: The table is quite complicated, rows within columns and all, so plugins like ALASQL, JS-XLSX is not helping.
推荐答案
问题可能出在XLSX类型.这篇文章指出,这是一组压缩的XLS文件.仔细阅读.我无法发表评论,因为我的分数还没有超过50,所以我将其发布为答案.
The problem may lie in the type XLSX. This post states that it is a zipped set of XLS files. Have a read through. I cannot comment, because my score isn't over 50 yet, so I'm posting as an answer.
https://stackoverflow.com/a/37516332/1425168
这篇关于下载XLSX损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!