Convert Json into Xlsx File

后端 未结 3 1222
自闭症患者
自闭症患者 2021-01-18 18:18

I am trying to covert json data into Xlsx file and save it in a folder. I have been trying to use icg-json-to-xlsx module but till now I have been unable to use it. My code

3条回答
  •  滥情空心
    2021-01-18 18:39

    There are a lot of modules that can do it. But if you want to control the formatting of xlsx file, then I suggest you use this below code. Rows contain data in the form of JSON array.

    var excel = require('node-excel-export');
    var styles = {
        headerDark: {
            fill: {
                fgColor: {
                    rgb: 'FF000000'
                }
            },
            font: {
                color: {
                    rgb: 'FFFFFFFF'
                },
                sz: 14,
                bold: true,
                underline: true
            }
        },
        cellPink: {
            fill: {
                fgColor: {
                    rgb: 'FFFFCCFF'
                }
            }
        },
        cellGreen: {
            fill: {
                fgColor: {
                    rgb: 'FF00FF00'
                }
            }
        }
    };
    
    var specification = {
        "Col1": {
            "displayName": 'Col1Name',
            "headerStyle": styles.headerDark,
            "width": 250
        },
        "Col2": {
            "displayName": 'Col2Name',
            "headerStyle": styles.headerDark,
            "width": 215
        },
        "Col3": {
            displayName: 'Col3Name',
            headerStyle: styles.headerDark,
            width: 150
        }
    }
    
    var report = excel.buildExport(
        [{
            name: 'Report.xlsx',
            specification: specification,
            data: rows
        }]
    );
    

提交回复
热议问题