2012-04-11 72 views
4

有人可以幫我畫一個excel單元格,通過rgb在matlab中嗎? 我希望第10格將由rgb繪製。
Matlab繪製一個excel單元格

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

你不能通過'xlswrite'來做到這一點,但必須改用ActiveX。例如在這裏看到:http://www.orient-lodge.com/node/3430 – Jonas 2012-04-12 03:04:04

+0

@Jonas 嗨,喬納斯,我改變了我的消息,因爲我有一個奇怪的問題。 我運行該程序,並且在我的目錄中創建了一個新文件,例如:2E60F720。它爲什麼被創建?我該如何解決它?我注意到,如果我通過任務管理器關閉'EXCEL.EXE',程序停止,並且我得到了這個:「???錯誤:遠程過程調用失敗 錯誤==> test1 at 212 ewb.Close(false);「 謝謝! – 2012-04-12 14:15:16

+0

單元格是否在excel文件中正確着色?在這種情況下,我建議你回答你的問題,接受@ yuk的答案,併爲你的完全不同的問題開一個新的問題。 – Jonas 2012-04-12 14:20:47

回答

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

相關問題