change excel spreadsheet color when exporting data
8 views (last 30 days)
Show older comments
Hi
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
xlswrite(xlsfile,[header; output],sheetText,'A2');
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
0 Comments
Answers (3)
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)
else
xlsfont(filename,sheetname,'Find',text2, color,color index number2)
end
Is this something you are trying to do? If so I would suggest you should try it,if you haven't tried it yet
0 Comments
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?
0 Comments
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.
10 Comments
KRUNAL
on 4 Aug 2014
Thank you. i will try to understand this file and based on it will try to create my own file from it. If required,will post questions on it here.
KRUNAL
on 5 Aug 2014
I tried running the 1st part.It basically creates a new excel file and then throws the error of file open and existing
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!