MATLABからExcelの背景色を一括で変えたい
Mostra commenti meno recenti
How to set excel cell color to red from Matlab?を参考にExcelの背景色の変更を試しています。
ここで'A1'だけの変更や単色での一括変更はできそうなのですが、複数のセルにそれぞれ指定した背景色に変えることができません。
%Obtain the full path name of the file
filePath = fullfile(pwd, 'Book1.xlsx');
%Open an ActiveX connection to Excel
h = actxserver('excel.application');
%Open an excel file
wb = h.Workbooks.Open(filePath,0,false);
例えば以下4マスの背景色を変えたいとき
% Sample cells
Imagecells = {'A1', 'B1'; 'A2', 'B2'};
bgrColorCell = {10604985, 10801852; 11588283, 11719614}; % BGR
現状は以下のように逐一座標を決めて変更しています。
cellfun(@(x,y) xlscolor(h, x, y), ImgCells, bgrColorCell)
% save the file with the given file name, close Excel
wb.Save;
wb.Close;
h.Quit;
h.delete;
関数は以下の通りです。
function xlscolor(h, range, Color)
ran = h.Activesheet.get('Range',range);
ran.interior.Color = Color;
end
これを
wb.Activesheet.interior.Color('A1:B2') = bgrColorCell;
のように一括で複数の色を変換できないでしょうか?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su スプレッドシート in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!