Classic asp - conditional formatting

Conditional formatting seems to be available to the classic asp environment.
I get the Add2ColorScale working just fine.
What I really need is the AddContainValue functionality, but I can’t get it to work.
I would greatly appreciate a working line of code for AddContainValue in classic asp.

Sample from documentation (vb .net) below:
'Apply green font color to cells in a ‘Years of Service’ column which have values between 15 and 20.
worksheet.ConditionalFormatting.AddContainValue(“C2:C” & (rowCount + 1), ContainValueOperator.Between, 15, 20) _
.Style.Font.Color = SpreadsheetColor.FromName(ColorName.Green)

Hi,

There are two AddContainValue overload methods, the first one takes 3 parameters and the second one takes 4 parameters:

public ContainValueCondition AddContainValue(string appliesTo, ContainValueOperator operator, object value)
public ContainValueCondition AddContainValue(string appliesTo, ContainValueOperator operator, object value, object value2)

I’m afraid that COM doesn’t support method overloads and thus only the first method is exposed.

The thing to note here is that the first method is for all ContainValueOperator values except for Between and NotBetween. The second method is for only Between and NotBetween values.

So, what you can do is call the first AddContainValue overload method with one of these integer values for the ContainValueOperator value:

  • 2 - for ContainValueOperator.Equal
  • 3 - for ContainValueOperator.NotEqual
  • 4 - for ContainValueOperator.GreaterThan
  • 5 - for ContainValueOperator.LessThan
  • 6 - for ContainValueOperator.GreaterThanOrEqual
  • 7 - for ContainValueOperator.LessThanOrEqual

In other words, try something like this:

' Apply bold font weight to cells in a 'Years of Service' column which don't have value 29.
worksheet.ConditionalFormatting.AddContainValue("C2:C100", 3, 29).Style.Font.Weight = 700

I hope this helps.

Regards,
Mario

Thanks :slight_smile: The example for font weight is perfect.
Could I use this for font color and cell background? I tried but failed.

Unfortunately no, the problem is that SpreadsheetColor struct is incompatible with COM.

Not all members of GemBox.Spreadsheet are accessible because of the COM limitations, so I would recommend you create a .NET wrapper library instead. Your wrapper library should do all the work within and expose a minimal set of classes and methods to the unmanaged code (COM).

This will enable you to take advantage of GemBox.Spreadsheet’s full capabilities, thus avoiding any COM limitations.

Regards,
Mario