如何解决此“未处理的拒绝TypeError:res.xls不是函数”

问题描述 投票:0回答:1

我得到'res.xls不是一个函数,我已经安装了所有必需的软件包,但无法解析。我想将json数组转换为xls文件。

我在MySql中使用node.js。

const express = require('express'); 
   const router = module.exports = express.Router(); 
   const json2xls = require('json2xls'); 
   router.use(json2xls.middleware);

    function convert (req, res) {
    var contacts = [{
                    name: 'Bob',
                    lastName: 'Smith'
                }, {
                    name: 'James',
                    lastname: 'David'
                }];
        res.xls('report.xlsx', contacts);
    }

我希望JSON数据应转换为xls文件。

arrays node.js json xls
1个回答
0
投票
    app.get('/',function(req, res) {
var contacts = [{
                    name: 'Bob',
                    lastName: 'Smith'
                }, {
                    name: 'James',
                    lastname: 'David'
                }];
        res.xls('report.xlsx', contacts);
    });
© www.soinside.com 2019 - 2024. All rights reserved.