Excel cell formatting - cannot figure out how to make it work
Excel cell formatting - cannot figure out how to make it work
I've read through the guide here: https://datatables.net/extensions/buttons/examples/html5/excelCellShading.html, and also looked at some forum posts where people use the customize
function, but for me formatting is not working.
I've downloaded the sample file you have at the above link, but there is no formatting in it for me when I open the saved file. I've also attempted to do this on my own without any luck. The code executes, but the downloaded file contains no additional formatting. Is there a particular version of Excel up to which this code works? I'm using Excel 2013.
This question has accepted answers - jump to:
Answers
It'll definitely work with excel 2013.
In the example you mention, the styling is applied by the code:
This means that if the value of the current cell in column F is greater than 500000, it gets the "s"tyle with number 20. Lookup the style number you want at the documentation of the
excelHtml5
Of course you'll need to adjust
with a jquery selector that fits your needs.
Interesting - Yours were some of the posts I had looked at
What's interesting though is that when I download Alan's example in the link above, there is no formatting. Is there formatting for you when you download the file?
Hmmm, indeed the example isn't working with me either in FF52.0.2
The problem could be the recently added auto detection of cells with currencies in them.
@Allen could you check your example? In my example below I also have problems with currency columns.
And if you want to see more styling examples, check my codepen.
Hey @F12Magic ,
Based on this code:
How would you iterate over each cell in a ROW, instead of a column? I'm looking to iterate over the header row and use a different
s
attribute depending on a few variables...Look in the JS pane of my codepen. There are comment lines above each code line explaining the selector. To iterate and style the cells you can use the same principle as you mentioned above. Something like below would do the job.
Yeah I grabbed this from your codepen, I just wasn't sure of the syntax for iterating over rows. This is perfect. Thank you!
In the event this helps anyone else, here's the ultimate code I used to check whether or not the following headers were in my output. If they were, I wanted rows with those specific names to be a different color.
@F12Magic wrote a nice example of how to loop through each cell in the first row
row:first
:I need to loop through each cell in the 3rd row and set the background color.
How would you specify the row selector for row n?
Following code is untested, but if css selectors work it should be OK.
On the other hand, I checked my codepen examples and found this working for sure: