Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to define conditional formating function of excel in MATLAB?

610 views
Skip to first unread message

Prashant

unread,
Feb 15, 2010, 12:48:03 PM2/15/10
to
Following is the program I am using to change the font color of cell when cellvalue is greater than -1000. I am using conditional formatting function of excel to do this. What should be the format of the code to do this?


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');

ExAct = Excel.Activesheet;
ExActRange = get(ExAct,'Range',range);
ExActRange.Select;
xlExpression=1;
Excel.Selection.FormatConditions.Delete;
Excel.Selection.FormatConditions.Add(xlExpression, [>], ['-1000']);
Excel.Selection.FormatConditions.Item(1).Font.ColorIndex = 56;

This program gives me following error:
??? Invoke Error, Dispatch Exception: Parameter not optional.

Amr

unread,
Jun 2, 2011, 9:05:21 AM6/2/11
to
Excel.Selection.FormatConditions.Add(xlExpression, [>], ['-1000']); this is not a correct syntax

you have to provide the operator corresponding value, as explained below:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.formatcondition.modify%28v=office.11%29.aspx


xlCellValue = 1

Excel.Selection.FormatConditions.Add(xlCellValue,Operator,Formula1,Formula2);


Operator:

1 = xlBetween
2 = xlNotBetween
3 = xlEqual
4 = xlNotEqual
5 = xlGreater
6 = xlLess
7 = xlGreaterEqual
8 = xlLessEqual

Formula 2 is only supported when "xlBetween" or "xlNotBetween" is used.

example:

Excel.Selection.FormatConditions.Add(xlCellValue,1,'-2','5'); % format when the value is between -2 & 5

Excel.Selection.FormatConditions.Add(xlCellValue,2,'-2','5'); % format when the value is NOT between -2 & 5

Excel.Selection.FormatConditions.Add(xlCellValue,3,'10'); % format when the value is equal 10

I know its a late reply, but it could help others who could search for the same issue.

Best Regards,


"Prashant " <prasru...@yahoo.com> wrote in message <hlc1cj$9ro$1...@fred.mathworks.com>...

0 new messages