How to apply conditional formatting of a cell in excel based on value in another cell using matlab?
5 次查看(过去 30 天)
显示 更早的评论
I am trying to automate conditional formatting in excel sheets generated using matlab. I have to format the color of a cell based on the value in the adjacent cell.
For example: I need to format the color of cells B2:B20 based on values from cells A2:A20.
This is the code I am using
Excel = actxserver('Excel.Application');
set(Excel,'Visible',0); Workbook = invoke(Excel.Workbooks, 'open', [fpath filesep file ext]);
sheet = get(Excel.Worksheets, 'Item',sheetname); invoke(sheet,'Activate');
%% range: cells that need to be formatted %% range1: cells that determine the formatting of range
ExAct = Excel.Activesheet; ExActRange = get(ExAct,'Range',range); ExActRange.Select;
xlExpression = 2; Excel.Selection.FormatConditions.Delete; Excel.Selection.FormatConditions.Add(xlExpression, [], ['=' range '=if(range1 = 6, 1)']); Excel.Selection.FormatConditions.Item(1).Interior.ColorIndex = 3;
invoke(Workbook, 'Save'); invoke(Excel, 'Quit'); delete(Excel);
Please let me know my mistake, and better if you could suggest an alternative that could get my job done.
Thanks
Bhaskar
0 个评论
回答(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!