change the change the color of excel sheet if it contains odd value in 1st column

9 vues (au cours des 30 derniers jours)
Akash Rana
Akash Rana le 31 Jan 2020
Réponse apportée : Rahul le 17 Fév 2025
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

Réponses (1)

Rahul
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.

Community Treasure Hunt

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

Start Hunting!

Translated by