ExcelHtml5 Export customize - get background color cell
ExcelHtml5 Export customize - get background color cell
Tito Bada
Posts: 4Questions: 1Answers: 0
Good morning, in excel export customize for example I can get the value of the specific cell with the function:
$('is t', this).text();
Is it possible to get the value of the background colour (define with html tag in <td>) of a specific cell?
Thank you if you can help me
Tito
This question has accepted answers - jump to:
Answers
Hi @Tito Bada ,
You can just use the
css
method:Cheers,
Colin
Hi Colin, thanks for your help!
I tried to use the feature you suggested, here is a quick summary, I hope to be concise:
In the generation of the cells of the table I use (for example):
<td style="background-color: #087c22"><?php echo $data?></td>
The column of cells in the excel file on which I am going to generate the background color is column K (verified after a test export).
To generate the excel file I use the following code:
This is just a test to verify the content of the variable.
Unfortunately the content of the variable "color" is always "undefined".
I'm definitely doing something wrong. I'm sorry.
Can you help me?
Thanks, bye!
Hi @Tito Bada ,
I think we may be talking cross purposes here - this is what I was referring. The console displays the RGB code for your
<td style="background-color: #087c22">
.Would you be able to modify that example to demonstrate your problem, please.
Cheers,
Colin
Hi Colin,
thanks for the example you gave me.
In practice I am in the following situation: I would like to create a table where in a given column there are numerical values. Some of these values are equal to 0. Some cells with 0 are represented with the background color orange, others with the color green (for different needs).
With html of course I solve with the "style tag" that I insert in the "td tag"
can be
td style="background-color: #ff8100"><?php echo $data?>
or
td style="background-color: #087c22"><?php echo $data?></td>
When I export in excel format, I would like to be able to read the background color code I have set and replicate it in the excel file.
In the example of the code I would like to do this:
in the example the value of the color variable is always equal to "undefined".
I don't know what to control in the
if(color == ........
Maybe you can't read in the customized excel function the value of a style tag displayed in html, or I'm wrong about reading or generating the variable.
I'll try to change your example to generate the problem, but if I'm doing something wrong let me know.
Sorry for my incompetence.
Cheers,
Tito
Hi @Tito Bada ,
Here you go, a nice Monday afternoon task! This is using "Red" and "Green" CSS, but you can modify the
if
statement to be any colour code.Hope that does the trick,
Cheers,
Colin
Hi @Colin,
this Monday afternoon I did the task and... it worked!
Really perfect! I understood how to act on the code.
Thank you for the example.
Thank you for solving the problem, and especially thank you for teaching.
Thank you so much.
Cheers,
Tito
Hi @Tito Bada ,
Can you please share your answer which fixed the issue because in my case also the value of the color variable is always equal to "undefined".
Thanks,
Sunny
Colin posted a working example.
Can you post a link to your page or a test case replicating the issue? Maybe you can update Colin's example with your code.
Kevin
@kthorngren : Actually in my scenario I have to loop over all the columns instead of a single column. I got it working now. Thanks for the guidance.
Hi @colin @kthorngren
In the working example , if I set the paging: true, the excel export with cell color is incomplete. How to make it work with paging ?
Oddly using
$(...).css('background-color')
will return an rgb colour on cells which have been drawn in the document, but will return a string (e.g.red
orgreen
) on cells which haven't yet been drawn.Adding a check for that fixes the export: http://live.datatables.net/horuxuxo/2/edit .
Allan
Hi @colin
this work great, but as like @Eswar4unow question, How to color color all the data , without see the paging page ? the color in excel only follow the 1'st page.
It's behaving as expected in Allan's test case. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.
Cheers,
Colin
Hi, what is the code of color yellow?
There isn't a built in style for yellow - see the full list here - if that was needed you would have to edit the XML doc
Colin