This task can be accomplished using ActiveX with Excel. The following example function shows one way to do this:
function xlscolor(file, data, range)
file = fullfile(pwd, file);
h = actxserver('excel.application');
wb=h.WorkBooks.Add();
ran = h.Activesheet.get('Range',range);
ran.value = data;
ran.interior.Color=hex2dec('00FF00');
ran.font.Color=hex2dec('FF0000');
wb.SaveAs(file);
wb.Close;
h.Quit;
h.delete;
end
Example invocation:
xlscolor('Tone.xls',rand(5,5),'A1:E5')
For more information on programming with Excel (For example, the commands like 'Add'), please consult the "Microsoft Excel Visual Basic Reference" via Excel's help menu.
For further information please refer to the following documentation:
For MATLAB R2017b:
1. ACTXSERVER:
>> web(fullfile(docroot, 'matlab/ref/actxserver.html'))
2. MATLAB software as an Automation client and the Microsoft® Excel® spreadsheet program as the server:
>> web(fullfile(docroot, 'matlab/matlab_external/supported-client-server-configurations.html#bq9yam7-8')
For the latest release documentation:
1. ACTXSERVER:
2. MATLAB software as an Automation client and the Microsoft® Excel® spreadsheet program as the server:
Information on the hexadecimal notation of colors values (IMPORTANT: please note, Microsoft uses BGR ordering as opposed to the RGB notation explained below)