简体   繁体   中英

How to add title row and cell formatting when exporting data to excel using alasql in angular js application?

In my angular application I want to export the data to an excel file, I have used alasql for the same. How do I add the title which should be a row with cell merged and also show the filter parameters on which the data is generated in the excel sheet?

var mystyle = {
    headers: true,
    column: { style: { Font: { Bold: "1" } } },
};

let dataCopy = JSON.parse(JSON.stringify(dataFiltered));
alasql('SELECT * INTO XLSX("' + reportName + '",?) FROM ?', [mystyle, dataCopy]);

I have filterParams array which contains the filter parameters with value in the key value pair.

I want to generate the excel sheet with the title of the table in the first row below which the data should be generated. After the title should come the parameters which are to be displayed.

ALASQL doesn't support merging cells or applying filters. But you can add a title/header row. You need to create a header row with the same number of columns and same keys as your data has. Then merge this header row with your data and import in excel.

var headers = alasql('select "Title 1" as Key1, "Title 2" as Key2, "Title 3" as Key3');
let dataCopy = JSON.parse(JSON.stringify(dataFiltered));
var mergedArray = $.merge(headers, dataCopy);
alasql('SELECT * INTO XLSX("' + reportName + '",?) FROM ?', [mystyle, mergedArray]);

Please accept the answer if it solves your problem. Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM