ALASQL - Excel from Json- Styling in multiple sheets

末鹿安然 提交于 2021-02-08 09:55:14

问题


I am trying to use alasql to download excel file having json data, and it works quite effectively, but I am stuck in a scenario where I need help. Scenario - I have an array of 2 json objects and I want to download 1 excel sheet with two tabs each for 1 object, that works effectively, but I want to add some styling to it, but if I try to add styling using options then it fails and the excel shows different output having [object object] format. Whereas if I try the same styling with one data object it works fine and gives the required output.

Part 1: Two objects download in one sheet without style

var data1 = [{a:1,b:10},{a:2,b:20}];
var data2 = [{a:100,b:10},{a:200,b:20}];
var data = [data1,data2];
var dashboardName = "test";
var opts = [{sheetid:'One',headers:true},{sheetid:'Two',headers:true}];
var sql = 'SELECT INTO XLSX("' + dashboardName + '.xls",?) FROM ?';
var res = alasql(sql, [opts, data]);

Part 2: One object download in one sheet with style

var data1 = [{a:1,b:10},{a:2,b:20}];
var data2 = [{a:100,b:10},{a:200,b:20}];
var data = [data1,data2];
var dashboardName = "test";
var opts = {
            sheetid:'One',
            headers:true,
            rows: {
                0: {
                    cell: {
                        style: 'font-size:17px;background:#115ea2;color:white;font-weight:bold'
                    }
                }
            }
        };
var sql = 'SELECT * INTO XLS("' + dashboardName + '.xls",?) FROM ?';
var res = alasql(sql, [opts, data1]);

Part 3: Actual Requirement (Two objects download in one sheet with style)

var data1 = [{a:1,b:10},{a:2,b:20}];
var data2 = [{a:100,b:10},{a:200,b:20}];
var data = [data1,data2];
var dashboardName = "test";
var opts = [{
            sheetid:'One',
            headers:true,
            rows: {
                0: {
                    cell: {
                        style: 'font-size:17px;background:#115ea2;color:white;font-weight:bold'
                    }
                }
            }
        },{
            sheetid:'Two',
            headers:true,
            rows: {
                0: {
                    cell: {
                        style: 'font-size:17px;background:#115ea2;color:white;font-weight:bold'
                    }
                }
            }
        }];
var sql = 'SELECT * INTO XLS("' + dashboardName + '.xls",?) FROM ?';
var res = alasql(sql, [opts, data]);

output of 1:

output of 2:

output of 3:

Please let me know if I am doing something wrong, or is there some other way to implement the requirement

Thanks in advance :)

来源:https://stackoverflow.com/questions/64212306/alasql-excel-from-json-styling-in-multiple-sheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!