Set Excel cell style based on DataTable cell class
Set Excel cell style based on DataTable cell class
Im wondering if there's a way to style an excel cell based on DataTables corrisponding cell class.
Example:
$('row:eq(1) c[r^="B1"]', sheet).hasClass('custom').attr( 's', '5' );
or
$('row c[r^="B"]', sheet).each( function (){
if ( $('is t', this).hasClass( 'custom ) ) {
$(this).attr('s', '1');
}
});
Basically I'm working on a row of cells (more than 30, so I have AA, AB, AC and so on) and i need a method to discriminate some of them to add a different style, let's say the header has 31 cells with calendars day/name as header and i want the colums with Saturday and Sunday to be with a gray background.
This is the datatable:
And this is the excel file so far, i need the Sab and Dom columns to be gray
thank you
Answers
If you know that Sab / Dom are always going to be columns I / J / P / Q / etc, then you could base the styling on that. That would mean that you always start the week on the same day.
If that isn't an option, then I fear this is going to be somewhat more tricky, as by the time the
customize
function runs, you don't have a reference to the cells any more. I think you'd probably need to do a reverse lookup to go from the cell location to the DataTable cell...Allan
Hi Allan, the table is dinamically builded with
php foreach() loop
so the position of the Sab/Dom may vary (in this case you're looking at June monthly table with 30 days, July first occurrence of Sab/Dom will be on colums G/H.
Currently I'm triyng to use this answer from Stackoverflow where I posted the same question.
and this is what i get:
It works, but the loop picks only the first occurrence of each
rowspan (merged cells)
in the excel file i guess because it fails wit AA, AB, ACAny idea? Thanks
The solution above was already working, the cells in the Sab,Dom cols in the excel file doesn't have the grey background beacause they are missing the class .Sab, .Dom in the datatable cells (I gave the class only to the first row before to write the code for the whole table and than i forgot that!). The problem still remain for the cells with double letters: AA, AB, AC, AD, AE ...
I found this solution on Stackoverflow .
Mixed together they work as i need, here is my solution:
and here is the result:
one last effort would be to style the cells with the thick border with their own style, but for now it's ok, thanks.