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!