FileSaver.js saveAs(Xlsx)

时间:2017-02-19 00:58:04

标签: angularjs filesaver.js

我正在使用filesaver.js将我的div(带有多个表)导出为ex​​cel。我可以使用下面的代码将其导出为XLS。

var blob = new Blob([document.getElementById('exportable').innerHTML], {
    type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Test Report using FileSaver.xls");

但是,我想将我的div导出到XLSX。有人可以帮忙吗?我尝试将MIME类型更改为XLSX,但没有帮助。

1 个答案:

答案 0 :(得分:1)

<强>更新 W3C没有实现Would you like overnight delivery [Y/N]? Y Today's Date: 03-25-2017 Your Expected Arrival Date: 03-26-2017 Would you like overnight delivery [N/Y]? N Today's Date: 03-25-2017 Your Expected Arrival Date: 03-28-2017 所以浏览器也是如此。但您可以使用.xlsx js库将数据导出为有效alsql,此处为jsfiddle或在代码下运行

&#13;
&#13;
.xlsx
&#13;
function myCtrl($scope) {
    $scope.exportData = function () {
        alasql('SELECT * INTO XLSX("Report.xlsx",{headers:true}) FROM ?',[$scope.items]);
    };
    
    $scope.items = [{
        name: "John Smith",
        email: "j.smith@example.com",
        dob: "1985-10-10"
    }, {
        name: "Jane Smith",
        email: "jane.smith@example.com",
        dob: "1988-12-22"
    }, {
        name: "Jan Smith",
        email: "jan.smith@example.com",
        dob: "2010-01-02"
    }, {
        name: "Jake Smith",
        email: "jake.smith@exmaple.com",
        dob: "2009-03-21"
    }, {
        name: "Josh Smith",
        email: "josh@example.com",
        dob: "2011-12-12"
    }, {
        name: "Jessie Smith",
        email: "jess@example.com",
        dob: "2004-10-12"
    }];
};
&#13;
&#13;
&#13;