Convert Json into Xlsx File

后端 未结 3 1238
自闭症患者
自闭症患者 2021-01-18 18:18

I am trying to covert json data into Xlsx file and save it in a folder. I have been trying to use icg-json-to-xlsx module but till now I have been unable to use it. My code

3条回答
  •  梦谈多话
    2021-01-18 18:59

    You can try Alasql JavaScript SQL library. It includes a module to work with JSON and XLSX files (with support of js-xlsx.js library).

    Install these two libraries into your project.

    npm install alasql
    npm install xlsx
    

    Then call alasql function:

    var alasql = require(alasql);
    alasql('SELECT * INTO XLSX("mydata.xlsx",{headers:true}) \
                FROM JSON("mydata.json")');
    
    var cities = [{City:'London',Population:2500000},{City:"Paris",Population:2000000}];
    alasql("SELECT * INTO XLSX("mydata.xlsx",{headers:true}) FROM ?",[cities]);
    

    See more examples in this demo file.

提交回复
热议问题