ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: TraTech on December 01, 2021, 10:14:00 pm

Title: Export Option works only if the color is mentioned in Hex-Code
Post by: TraTech on December 01, 2021, 10:14:00 pm
Hello Support-Team,

The "Export" Option works only if the colour of the column or row is mentioned in Hex-Code.
If the colour is mentioned as 'red' or 'green', it's correctly displayed in the grid, but when the "Export" option is clicked, nothing happens.
In the web console an error message "Uncaught invalid colour: red" is present.

Please advise if there is a workaround for this.

Thanking you in advance.

Best regards,

Title: Re: Export Option works only if the color is mentioned in Hex-Code
Post by: paramvir on December 02, 2021, 07:40:12 am
Hi TraTech

Yes there is a workaround.

Step1: First export to js workbook.

Step 2: replace string color values with hex values in the workbook.

Step 3: export to xlsx.

Code: [Select]
listener: function() {
var colors = {
red: '#FF0000',
yellow: '#FFFF00',
green: '#00FF00',
blue: '#0000FF'
}
        var wb = this.exportExcel({workbook: true});

pq.excel.eachCell(wb.sheets, function( cell, ci, ri, si ){
//do something with each cell.
cell.color = colors[cell.color] || cell.color;
});
     var blob = pq.excel.exportExcel({workbook: wb, type: 'blob'});
     saveAs(blob, "pqGrid.xlsx" );
 }


Hope it helps.
Title: Re: Export Option works only if the color is mentioned in Hex-Code
Post by: TraTech on December 02, 2021, 12:15:36 pm
Hello Paramvir,

Thankyou for the quick reply.
Is there a new library required to use the workbook-js?
We are using the "FileSaver.js" to perform the export option.

Is there any example that I could refer to view how this works.

Thanking you in advance!

Best regards,
Title: Re: Export Option works only if the color is mentioned in Hex-Code
Post by: paramvir on December 02, 2021, 10:17:28 pm
Hi TraTech

js workbook is part of paramQuery and doesn't require any other library.

Structure of js workbook: https://paramquery.com/pro/api/excel-workbook

These 2 examples show usage of js workbook.

https://paramquery.com/pro/demos/export_detail
https://paramquery.com/pro/demos/export_sheets

Please also refer to this API

https://paramquery.com/pro/api#method-eachCell
https://paramquery.com/pro/api#method-exportExcel
https://paramquery.com/pro/api#method-exportWb