change excel spreadsheet color when exporting data
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
KRUNAL
2014-7-29
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 个评论
KRUNAL
2014-8-1
编辑:KRUNAL
2014-8-1
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 个评论
Image Analyst
2014-8-1
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 个评论
KRUNAL
2014-8-4
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
2014-8-5
I tried running the 1st part.It basically creates a new excel file and then throws the error of file open and existing
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!