请问有人能帮我在Matlab中通过RGB来填充Excel中的单元格吗? 我想让第10个单元格用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}]);
非常感谢你:]
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
hex2dec
函数。在这种情况下,顺序应该相反,例如对于红色应为0000FF
。
xlswrite
来实现这个,而必须使用 ActiveX。例如,可以参考这里:http://www.orient-lodge.com/node/3430 - Jonas