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}]);
非常感谢你:]
答案 0 :(得分:4)
您可以使用以下过程为现有文件中的单元格着色:
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
您还可以使用十六进制值指定RGB颜色并使用hex2dec
。在这种情况下,顺序应该相反,例如红色0000FF
。