问题
can someone help me please in painting an excel cell through rgb in matlab?
I want that the 10th cell will painted by rgb.
values{1}(1,:) = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'};
headers = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
xlswrite('example.xls', [headers; values{1}]);
thank you a lot :]
回答1:
You can color cells in an existing file with a procedure like this:
values = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'};
headers = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
rgb = [255 0 0]; %# if you have 0 to 1 values multiply by 255 and round
clr = rgb * [1 256 256^2]'; %'# convert to long number Excel understands
e = actxserver ('Excel.Application'); %# open Activex server
filename = fullfile(pwd,'example.xls'); %# full path required
if exist(filename,'file')
ewb = e.Workbooks.Open(filename); %# open the file
else
error('File does not exist.') %# or create a new file
end
esh = ewb.ActiveSheet;
for c = 1:numel(values)
esh.Range(strcat(headers{c},values{c})).Interior.Color = clr;
end
ewb.Save
ewb.Close(false)
e.Quit
You can also specified RGB color with hex values and use hex2dec
. In this case the order should be opposite, like 0000FF
for red.
来源:https://stackoverflow.com/questions/10115265/matlab-paint-an-excel-cell