Interop - "Unable to set the Color property of the Interior class"

G

Guest

Hello! I am begging for your help...

I am using the Excel interop (Microsoft Excel 11.0 Object Library, version
1.5.0.0) to open an existing workbook and adding conditional formats to
certain cells to mimic "hidding" them. I keep receiving exceptions from the
"Microsoft Office Excel" interop to the effect that I cannot set the font's
color and the interior's color. If you know, could you please reply to this
posting?

Thanks!

The C# code is as follows:

conditionalFormat =
conditionalFormats.Add(Excel.XlFormatConditionType.xlExpression
, System.Reflection.Missing.Value ,
(object)formulas.ToString(), System.Reflection.Missing.Value);
conditionalFormat.Font.Color = 0xff00; // triggers the
"Unable to set the Color property of the Font class"
conditionalFormat.Interior.Color = 0xff00; // triggers
the "Unable to set the Color property of the Interior class"
// conditionalFormat.Font.ColorIndex = 19; Triggers the
"Unable to set the ColorIndex property of the Font class"
// conditionalFormat.Interior.ColorIndex = 19; Triggers
the "Unable to set the ColorIndex property of the Interior class"
 
G

Guest

The reason of this error was that the worksheet was protected. I unprotected
it and now almost 70% of the conditional formats are successful. The ones
that are problematic are those that have the inequality operator "<>" along
with a number, as in the following (the named range does exist, the thread is
US):

=OR((IF(ISBLANK(Q36540A4),0,Q36540A4))<>0)

Even if I use NOT to avoid using the <>, as the following:

=OR((NOT(IF(ISBLANK(Q36325A3),0,Q36325A3))=0))

I get an error "Exception from HRESULT: 0x800A03EC" with stack trace as
follows:

at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.FormatConditions.Add(XlFormatConditionType Type, Object
Operator, Object Formula1, Object Formula2)
at Gartner.Decm.BusinessLayer.ExportToExcel.CreateCellHideCriteria(Range
cellRange, StringBuilder formulas) in
D:\Versioning\Aurora\trunk\DECMBusinessLogic\Utilities\ExportToExcel.cs:line
1101

Also, would anybody know the translation from RGB to hexadecimal for color R
253, G 250, B 255?

Many thanks for any information that you can provide.

Elsa
 
N

NickHK

VB/VBA has the RGB() function to return a Long from the 3 components.
Couldn't tell you about C#.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top