1

我正在尝试创建一个向用户导出(下载)excel文件的nodejs应用程序,当我点击url(/下载)并且下载的文件正常时,相同的代码在localhost上运行良好,但是当我将相同的代码上传到lambda时,它返回损坏的文件。请在这件事上给予我帮助:

router.get('/download', function (req, res, next) {
  var result = [
    { emp_username: 'ABC', emp_name: 'ABCDEF', emp_address: '52nd Downtown', emp_department: 'Reasearch & Analysis', emp_salary: 113000, emp_doJoin: '2018-11-05' },
    { emp_username: 'BCD', emp_name: 'BCDEFG', emp_address: '1st W DC', emp_department: 'Accounts', emp_salary: 60000, emp_doJoin: '2017-01-02' },
    { emp_username: 'CDE', emp_name: 'CDEFGH', emp_address: '5th St Capital State', emp_department: 'Finance', emp_salary: 250000, emp_doJoin: '2017-10-18' },
    { emp_username: 'DEF', emp_name: 'DEFGHI', emp_address: '3rd SanJose CA', emp_department: 'Administration', emp_salary: 623000, emp_doJoin: '2004-06-01' }
  ];

  var wb = new excel.Workbook();

  var ws = wb.addWorksheet('Sheet1'); //add worksheets to workbook

  ws.cell(1, 1).string('Username');
  ws.cell(1, 2).string('Fullname');
  ws.cell(1, 3).string('Address');
  ws.cell(1, 4).string('Department');
  ws.cell(1, 5).string('Salary');
  ws.cell(1, 6).string('Date of Joining');
  ws.row(1).setHeight(25);

  for (var x = 0; x < result.length; x++) {
    ws.cell(x + 2, 1).string(result[x]['emp_username']).style(rowStyle);
    ws.cell(x + 2, 2).string(result[x]['emp_name']).style(rowStyle);
    ws.cell(x + 2, 3).string(result[x]['emp_address']).style(rowStyle);
    ws.cell(x + 2, 4).string(result[x]['emp_department']).style(rowStyle);
    ws.cell(x + 2, 5).number(result[x]['emp_salary']).style(rowStyle);
    ws.cell(x + 2, 6).date(result[x]['emp_doJoin']).style(rowStyle);
  }
  wb.write('Employees.xlsx', res);
});
4

0 回答 0