excelhtml5 Color predefine
excelhtml5 Color predefine
Khang
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
This discussion has been closed.
Answers
Do you mean the styles identified here? If so, then yes, you can use the
customize
callback method of theexcelHtml5
button type to modify the Excel XML. DataTables doesn't define an API for that, you'd need to modify the XML directly.Allan
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 nestedis
andt
.Perhaps you can add an example based on my testcase for future referece, as it is a recurring question about adding predefined styles.
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.
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 ?
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 ofcellXf
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.