Excel Interop: Range.FormatConditions.Add throws MissingMethodException

Posted by Zach Johnson on Stack Overflow See other posts from Stack Overflow or by Zach Johnson
Published on 2009-03-13T22:20:33Z Indexed on 2010/06/02 0:03 UTC
Read the original article Hit count: 517

I am writing an application which uses the Microsoft.Office.Interop.Excel assembly to export/import data from Excel spreadsheets. Everything was going fine (except for 1 based indexing and all those optional parameters!), until I tried to use conditional formatting. When I call Range.FormatConditions.Add I get a MissingMethodException telling me that no such method exists. This happens in both Vista and XP.

Here's an example of the code that generates the exception:

//1. Add a reference to Microsoft.Office.Interop.Excel (version 11.0.0.0)
//2. Compile and run the following code:

using Microsoft.Office.Interop.Excel;

class Program
{
    static void Main(string[] args)
    {
        Application app = new Application();
        Workbook workbook = app.Workbooks[1];
        Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
        Range range = worksheet.get_Range("A1", "A5");
        FormatCondition condition = range.FormatConditions.Add(
            XlFormatConditionType.xlCellValue, 
            XlFormatConditionOperator.xlBetween, 
            100, 
            200);
    }
}

© Stack Overflow or respective owner

Related posts about .NET

Related posts about excel