Is it possible to use matlab to identify excel cell colours and give value to specific colours?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
If so, can anybody advise on how to do this?
0 commentaires
Réponses (1)
Image Analyst
le 1 Jan 2017
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 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!