Author Topic: Export Option works only if the color is mentioned in Hex-Code  (Read 722 times)

TraTech

  • Pro OEM
  • Newbie
  • *
  • Posts: 2
    • View Profile
Export Option works only if the color is mentioned in Hex-Code
« 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,


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6210
    • View Profile
Re: Export Option works only if the color is mentioned in Hex-Code
« Reply #1 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.

TraTech

  • Pro OEM
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Export Option works only if the color is mentioned in Hex-Code
« Reply #2 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,

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6210
    • View Profile
Re: Export Option works only if the color is mentioned in Hex-Code
« Reply #3 on: December 02, 2021, 10:17:28 pm »