json2xls icon indicating copy to clipboard operation
json2xls copied to clipboard

Update json2xls.js

Open YoannB opened this issue 8 years ago • 1 comments

Added custom config or global config to use style.xml.

Then we can use in config :

var conf = {
                style: 'excel-style.xml',
                width: 50,
                captionStyleIndex: 1,
                beforeCellWrite: function (row, cellData, eOpt) {
                    // filled cell
                    if (cellData !== undefined && cellData !== '') {
                        eOpt.styleIndex = 1;
                    }
                    // line question
                    if (row[0].length === 0) {
                        eOpt.styleIndex = 2;
                    }
                    // cell email
                    if (row[0] === cellData) {
                        eOpt.styleIndex = 3;
                    }
                    // error
                    if (cellData === 'undefined') {
                        eOpt.styleIndex = 4;
                    }
                    eOpt.cellType = 'string';
                    return cellData;
                }
            };

or for each column :

var conf = {
                style:  'excel-style.xml',
                cols: [
                    {
                        width: 100,
                        captionStyleIndex: 4, // index cellXfs
                        cellType: 'string',
                        beforeCellWrite : beforeCellWrite
                    },
                    {
                        width: 30,
                        captionStyleIndex: 4, // index cellXfs
                        cellType: 'string',
                        beforeCellWrite : beforeCellWrite
                    },
                    {
                        width: 30,
                        captionStyleIndex: 4, // index cellXfs
                        cellType: 'string',
                        beforeCellWrite : beforeCellWrite
                    }
                ]
            };

YoannB avatar Apr 07 '16 10:04 YoannB

I like the ideas. Could you:

  • make sure the tests pass
  • add a description of the new config options to the readme
  • add an extra example to work with those options

rikkertkoppes avatar Jul 01 '16 09:07 rikkertkoppes