Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update json2xls.js #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update json2xls.js #14

wants to merge 1 commit into from

Conversation

YoannB
Copy link

@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
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