NodeJS : smart JSON conversion to Excel file

前端 未结 1 384
一生所求
一生所求 2021-01-25 19:12

I\'m working in NodeJS and I would like to export a JSON-format object to an Excel file.

I am well aware that there are (at least) three npm packages for that purpose, b

相关标签:
1条回答
  • 2021-01-25 19:26

    You can write to csv (comma-separated values) text file without any additional library. This extension open in Excel by default.

    var fs = require('fs');
    var file = fs.createWriteStream('file.csv', {'flags': 'w', autoClose: true});
    var result = '';
    for (var hashkey in myObject) 
        result += hashkey + ';' + myObject[hashkey].keyA + ';' + myObject[hashkey].keyB + '\n';
    file.write(result); 
    
    0 讨论(0)
提交回复
热议问题