问题
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