Is it possible to use matlab to identify excel cell colours and give value to specific colours?
5 ビュー (過去 30 日間)
古いコメントを表示
If so, can anybody advise on how to do this?
0 件のコメント
回答 (1 件)
Image Analyst
2017 年 1 月 1 日
Yes. You'll have to use ActiveX. I've attached a demo, but the demo doesn't check colors of cells. What you can do when you don't know the ActiveX commands is to try to do the same thing in Excel first. If you can do it in Excel, then record a macro to do it and then when you edit the macro you'll see the commands. Then you can transfer the command to MATLAB.
In the meantime, here is an ActiveX function I wrote to color the background of a cell in Excel:
%----------------------------------------------------------------------
% Fills the background color of the Excel cell with the specified color.
% Sample call:
% Set the color of cell "A1" of Sheet 1 to Yellow
% FormatCellColor(Excel, cellReference, 6)
function FormatCellColor(Excel, cellReference, cellFillColorIndex)
try
Excel.Worksheets.Item(1).Range(cellReference).Interior.ColorIndex = cellFillColorIndex;
catch ME
errorMessage = sprintf('Error in function FormatCellColor.\n\nError Message:\n%s', ME.message);
fprintf('%s\n', errorMessage);
WarnUser(errorMessage);
end % from FormatCellColor
return;
end
We can see from that code above, that the way to retrieve the existing cell background color in Excel, from MATLAB code, is probably
cellFillColorIndex = Excel.Worksheets.Item(1).Range(cellReference).Interior.ColorIndex
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!