excelhtml5 Color predefine

excelhtml5 Color predefine

KhangKhang Posts: 6Questions: 2Answers: 0

Hi,
I would like to know if there is a way to add more color or change predefine color. I tried to change fgColor in datatables.js but it doesnt work.
Thanks in advance for helping.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin

    Do you mean the styles identified here? If so, then yes, you can use the customize callback method of the excelHtml5 button type to modify the Excel XML. DataTables doesn't define an API for that, you'd need to modify the XML directly.

    Allan

  • HPBHPB Posts: 73Questions: 2Answers: 18
    edited June 2017 Answer ✓

    I've made a testcase to show how to add an extra predefined style.
    This code will add a new style that defines a red background and applies it to a specific column and value.
    live.datatables.net/redorefa/1/edit

    I'd highly recommend to extract the generated .xlsx file and open xl/styles.xml to learn what possibilities there are. (the .xlsx file is nothing more than a set of files zipped together)

    @allan
    As a sidenote, the example of adding a different cell background is broken since you define numeric values as a v node now, instead of nested is and t.

    Perhaps you can add an example based on my testcase for future referece, as it is a recurring question about adding predefined styles.

  • KhangKhang Posts: 6Questions: 2Answers: 0

    Thanks for answer i wasnt able to reply earlier
    @allan what i meant was just like what HPB said.
    @HPB thank you so much for that answer. That is what i searched for.

  • ArudianArudian Posts: 11Questions: 5Answers: 1

    Hi,
    the answer provided by @HPB helps me a lot, but i am not sure how to add multiple colors...this one adds red if condition is true, how do i add green if another condition is true.

    I don't get this part : $(this).attr('s', cellXfCount);
    Could someone please help me out ?

  • HPBHPB Posts: 73Questions: 2Answers: 18
    edited June 2017

    It is the index of the cellXf node. (zero-based)

    In the testcase I only added 1 cellXf node, so the index of it was the same as the original amount of cellXf nodes. Hence I used cellXfCount as the index.

    If you're adding more styles you should keep track of their index to reference it later in the s attribute.

This discussion has been closed.