Javascript '的文件格式和扩展名;文件.xls';don';与fileSaver.js不匹配
我想在excel文件中保存一个html表格,我使用fileSaver来保存。但当我下载文件并试图打开它时,我收到一个恼人的excel弹出窗口,上面写着 “report.xls”的文件格式和扩展名不匹配。该文件可能已损坏或不安全。除非您信任其来源,否则不要打开它。是否仍要打开它?” 如何修复此弹出窗口?谢谢。我也有类似的问题 我想我忘了在HTTP请求中将Javascript '的文件格式和扩展名;文件.xls';don';与fileSaver.js不匹配,javascript,angularjs,excel,blob,filesaver.js,Javascript,Angularjs,Excel,Blob,Filesaver.js,我想在excel文件中保存一个html表格,我使用fileSaver来保存。但当我下载文件并试图打开它时,我收到一个恼人的excel弹出窗口,上面写着 “report.xls”的文件格式和扩展名不匹配。该文件可能已损坏或不安全。除非您信任其来源,否则不要打开它。是否仍要打开它?” 如何修复此弹出窗口?谢谢。我也有类似的问题 我想我忘了在HTTP请求中将responseType设置为blob。 这似乎是正确读取二进制数据所必需的 例如: $http({ url: 'your/webserv
responseType
设置为blob
。
这似乎是正确读取二进制数据所必需的
例如:
$http({
url: 'your/webservice',
method: "POST",
data: json, //this is your json data string
headers: {
'Content-type': 'application/json'
},
responseType: 'blob'
}).success(function (data, status, headers, config) {
var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}).error(function (data, status, headers, config) {
//upload failed
});
代码来自。该格式的正确扩展名不是.htm。xls@musa:谢谢你的回答,但我想在excel中提取它,而不是htmlIt是html,excel希望该类型的文件具有.htm扩展名。指定扩展名不会将数据从一种格式转换为另一种格式。我发现这个答案非常有用
$http({
url: 'your/webservice',
method: "POST",
data: json, //this is your json data string
headers: {
'Content-type': 'application/json'
},
responseType: 'blob'
}).success(function (data, status, headers, config) {
var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}).error(function (data, status, headers, config) {
//upload failed
});