change the change the color of excel sheet if it contains odd value in 1st column
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have one excel file which contain both string and numeric value .First column contains number ony, I have to change the colour of entire row of the paticular column if it contains odd number value. I know to use actserver little bit
0 commentaires
Réponses (1)
Rahul
le 17 Fév 2025
In order to achieve the desired task, consider using 'actxserver' functions and access the particluar column containing numeric values. You can loop through those values and check if they are odd or even. Here is an example:
% Open Excel and workbook
excelApp = actxserver('Excel.Application');
excelApp.Visible = true;
workbook = excelApp.Workbooks.Open('C:\path\to\your\file.xlsx');
sheet = workbook.Sheets.Item(1);
% Loop through first column, change row color if odd
for i = 1:sheet.UsedRange.Rows.Count
value = sheet.Cells.Item(i, 1).Value;
if isnumeric(value) && mod(value, 2) ~= 0
sheet.Rows.Item(i).Interior.Color = 65535; % Yellow
end
end
% Save and clean up
workbook.Save();
workbook.Close();
excelApp.Quit();
delete(excelApp);
The following MATLAB Answers can be referred:
The following MathWorks documentations can be referred:
Thanks.
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!