Skip to content

Update json2xls.js#14

Open
YoannB wants to merge 1 commit intorikkertkoppes:masterfrom
YoannB:patch-1
Open

Update json2xls.js#14
YoannB wants to merge 1 commit intorikkertkoppes:masterfrom
YoannB:patch-1

Conversation

@YoannB
Copy link
Copy Markdown

@YoannB YoannB commented Apr 7, 2016

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
                    }
                ]
            };

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
                    }
                ]
            };
```
@rikkertkoppes
Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants