发布时间:2017-09-22编辑:佚名阅读(2422)
对比了 ExcelJS , https://github.com/guyonroche/exceljs#create-a-workbook
node-xlsx ,https://github.com/mgcrea/node-xlsx
等 nodejs 等现有组件,决定使用node-xlsx。
node-xlsx 基于现有前端强大组件 js-xlsx, https://github.com/SheetJS/js-xlsx
使用例子:
var express = require('express'); var router = express.Router(); var xlsx = require('node-xlsx'); var fs = require('fs'); /* GET import excel test. */ router.get('/importExcel', function(req, res, next) { var filename='./public/test.xlsx'; console.error(filename); // read from a file var obj = xlsx.parse(filename); console.log(JSON.stringify(obj)); res.send('import successfully!'); }); /* GET export excel test. */ router.get('/exportExcel', function(req, res, next) { // write var data = [[1,2,3],[true, false, null, 'sheetjs'],['foo','bar',new Date('2014-02-19T14:30Z'), '0.3'], ['baz', null, 'qux']]; var buffer = xlsx.build([{name: "mySheetName", data: data}]); fs.writeFileSync('b.xlsx', buffer, 'binary'); res.send('export successfully!'); });
1人
0人
0人
0人