MATLABからEx​celの背景色を一括​で変えたい

10 visualizaciones (últimos 30 días)
Hernia Baby
Hernia Baby el 7 de Dic. de 2023
Comentada: Hernia Baby el 7 de Dic. de 2023
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;
のように一括で複数の色を変換できないでしょうか?

Respuesta aceptada

交感神経優位なあかべぇ
交感神経優位なあかべぇ el 7 de Dic. de 2023
おそらく、複数色の背景色を一括で変更することはできません。
VBA上で、複数セルを選択したセルオブジェクト(Range("A1:C1"))に対して、Array配列を使用すれば、異なる値の代入は可能ですが、背景色の代入は対応しておらず、MATLAB上でも同様に複数色の背景色を一括変更することはできないと考えられます。
ちなみにですが、異なる値をセルの値に代入することは、MATLAB上でも可能です。
  1 comentario
Hernia Baby
Hernia Baby el 7 de Dic. de 2023
やはりそうですよねえ。いろいろ試しましたが色の変更は難しそうでした。ありがとうございました( ‘ᾥ’ )b

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!