如何将数据从Web管理员导出到excell

时间:2019-06-20 06:51:33

标签: javascript reactjs react-native

让数据=等待Users.query()             .select('users.nama','users.telepon','users.nama perusahaan','users.keperluan')             .leftJoinRelation('guestbook')             .whereBetween('users.created_at',[ctx.request.body.start_date,ctx.request.body.end_date])

    if (data.length === 0) {
        ctx.status = 400;
        ctx.body = {
            message: 'Data for selected date empty'
        };
        return;
    }
    let wb = new xl.Workbook();
    let ws = wb.addWorksheet('Sheet 1');
    let style = wb.createStyle({
        font: {
            color: '#000000',
            size: 12,
        },
        numberFormat: '$#,##0.00; ($#,##0.00); -',
    });

    Object.keys(data[0]).map((it, index) => {
        ws.cell(1, index + 1).string(it).style(style)
    });

    data.map((it, row) => {
        Object.keys(it).map((prop, col) => {
            ws.cell(row + 2, col + 1).string(it[prop]).style(style);
        });
    });
    let fileName = uuid.v4();
    await wb.write(path.join(__dirname, "../../uploads" + `/${fileName}.xlsx`));
    ctx.body = {
        url: '/uploads/' + fileName + ".xlsx"

0 个答案:

没有答案