change excel spreadsheet color when exporting data
16 views (last 30 days)
When I'm writing data out to excel, I would like to color code cells with values less than 0.0. I'm currently using xlswrite
where header is the column header for the data, and output is the numeric data being exported. I'm usually working with data sized 100 rows by 15 column.
I've seen scripts like http://www.mathworks.com/matlabcentral/fileexchange/4981-xlsfont--xlsalign--xlsborder--xlswordart--xlscomment/content/xlsfont.m and http://www.mathworks.com/matlabcentral/answers/102070-how-do-i-write-data-to-an-excel-spreadsheet-with-a-custom-cell-background-color-and-custom-font-colo that color cells, but they require you know the address of the cell beforehand...
I was wondering if there was a way to look and loop inside excel, find a negative number, highlight it red and loop to the next... Thanks
KRUNAL on 29 Jul 2014
Hey, even I am also facing the same issue. However after observing the 1st link you have posted I think you can do something like this:
%eg check the numbers that are greater than 100 in each row/column and should print 'bigger'(text1) in cells where you get num > 100 else print smaller(text2) %%
if num > 100
%whatever you want to output say any "text" %
xlsfont(filename,sheetname,'Find',text1, color,color index number1)
xlsfont(filename,sheetname,'Find',text2, color,color index number2)
Is this something you are trying to do? If so I would suggest you should try it,if you haven't tried it yet
KRUNAL on 1 Aug 2014
Edited: KRUNAL on 1 Aug 2014
I tried what I had asked you to do. However for me there was unusual thing that is happening. After reading all data, it does change color of the cell but it does only for the text that it gets for the 1st time out of the 10-12 cells containing the same text. Rest all are remaining the same and this happens in all the sheets of that excel file(I have 5-6 sheets in 1 excel file).What about you?
Image Analyst on 1 Aug 2014
Sure, you can do it. Either find out the cell addresses before you throw the data in there, or scan it afterwards. Either way you'll have to use ActiveX. Will you be willing to use ActiveX? You can use xlsfont but you'll have to modify it so that it doesn't launch and shutdown Excel every time you call it or else it will take an eternity to modify a bunch of cells.