使用 node-xlsx-writestream 可以操作 excel 文件。

1.1.1. 使用示例


var XLSXWriter = require('xlsx-writestream');
var fs = require('fs');

var fileName = "test.xlsx"

var writer = new XLSXWriter(fileName, {} /* options */);

var wirteStream = fs.createWriteStream(fileName)

// After instantiation, you can grab the readstream at any time.
writer.getReadStream().pipe(wirteStream);

// Optional: Adjust column widths
writer.defineColumns([
    {width: 30}, // width is in 'characters'
    {width: 10}
]);

// Add some rows
writer.addRow({
    "Name": "Bob",
    "Location": "Sweden"
});
writer.addRow({
    "Name": "Alice",
    "Location": "France"
});

// Add a row with a hyperlink
writer.addRow({
    "Name": {value: "Bill", hyperlink: "http://www.thegatesnotes.com"},
    "Location": "Seattle, Washington"
});

wirteStream.on('finish', function () {
    // finish
});
// Finalize the spreadsheet. If you don't do this, the readstream will not end.
writer.finalize();

Link

results matching ""

    No results matching ""