1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| var excelPort = require('excel-export'); var path = require('path') exports.write = function(req, res, next) { var datas = req.datas; var conf = {}; var filename = 'filename';
conf.cols = [{ caption: '学号', type: 'string', width: 20 }, { caption: '姓名', type: 'string', width: 40 }, { caption: '岗位', type: 'string', width: 200 }, { caption: '工时(h)', type: 'string', width: 200 }];
var array = []; array = [ [13084233, Jake, 图书馆, 20], [13084233, Jake, 图书馆, 20], [13084233, Jake, 图书馆, 20], [13084233, Jake, 图书馆, 20], [13084233, Jake, 图书馆, 20] ];
conf.rows = array; var result = excelPort.execute(conf);
var random = Math.floor(Math.random() * 10000 + 0); var uploadDir = path.join(__dirname, '../', '/public/files/') var filePath = uploadDir + filename + random + ".xlsx";
fs.writeFile(filePath, result, 'binary', function(err) { if (err) { console.log(err); } }); }
|