jQuery datatable export to excel with cell() background color

jQuery datatable export to excel with cell() background color

avinash_abhi95avinash_abhi95 Posts: 3Questions: 2Answers: 0
edited October 2020 in Free community support

Please find my code sample here: https://codepen.io/avinash-reddy95/pen/eYzORmJ

I am using jQuery datable to render a table and using dataTable export to Excel feature. I am able to export the excel successfully but I want to export to excel with cell back ground color if cell have any background color.

In above example column "Salary" have color red to some of the cells, I want to export with the colors. Could some one please help me on this?

Answers

  • kthorngrenkthorngren Posts: 20,315Questions: 26Answers: 4,771
    edited October 2020

    There are lots of threads discussing this. See if this or this helps.

    Kevin

  • avinash_abhi95avinash_abhi95 Posts: 3Questions: 2Answers: 0

    Thanks for the Answer @kthorngren and @tangerine. But I want to change my question little, I have multiple columns with colors(I have updated my code in codepen) also. Could you please let me know how to export to excel with color for multiple columns.

  • kthorngrenkthorngren Posts: 20,315Questions: 26Answers: 4,771

    I updated Allan's example in this thread to show one way to access all columns. Allan's example uses a specific selector ($('row c[r^="C"]', sheet) to loop through all the rows but only for the 3rd column. Removing c[r^="C"] allows access to all columns in each row.

    A loop is created to loop all the td cells in each row. If there is a background color it is set using the selector $('c[r^="' + excelMap[td] + '"]', row). excelMap[td] maps the column number to the Excel letter. You can do something more dynamic here if you wish.

    Hope this gets you started.

    http://live.datatables.net/horuxuxo/60/edit

    Kevin

This discussion has been closed.