How can I export a report with colour coding into excel so that all the color coding is intact in the excel sheet.

niharika2123
Tera Contributor

I am trying to export a report with color coding into excel sheet but unfortunately the colors are not showing up in the excel sheet. Also is theRE a possibility to export the report from a dashboard?

1 REPLY 1

athm
Tera Guru

Hi Niharika,



You can use


        window.open('data:application/vnd.ms-excel,' + encodeURIComponent("your_table_html_code_as_string_here"));



ex : In the below function, we can see a sample table with one row and two columns with each cell's background color defined in the bgcolor attribute of each cell. Save the table html code into a variable as string and use the above line to export the table to an excel sheet, it would retain the colors you defined in the html table in the excel you are about to export from the above method.



-->Create a html table and save it in a variable as string



var tab_text="<table border='2px'><tr>";


  tab_text = tab_text + "<td bgcolor = 'blue'>";


  tab_text = tab_text + "I AM BLUE";


  tab_text = tab_text + "</td>";


  tab_text = tab_text + "<td bgcolor = 'green'>";


  tab_text = tab_text + "I AM GREEN";


  tab_text = tab_text + "</td>";


  tab_text = tab_text + "</tr>";


  tab_text = tab_text + "</table>";//This will now have the table code as string in the variable tab_text



-->pass the variable to the below function, which you may call from a button you have created



function exportToExcel(tab_text){


  var exp = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));


  return (exp);


}



NOTE : The above works in Chrome/Mozilla. To make it work in IE refer to javascript - Is there any way to export html table into Excel working in all browsers? - Stack Overf...