Excel Interop: Range.FormatConditions.Add throws MissingMethodException

南楼画角 提交于 2019-12-10 11:21:07

问题


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

回答1:


This may be a good link for you: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/8a91d154-f766-427a-963c-16dfa39e154a/




回答2:


The Add() method for FormatConditions interface has 8 parameters, not 4. AFAIK there is no extension method in Excel.Extensions namespace for this type. Did you use an extension method in the example above or ...?



来源:https://stackoverflow.com/questions/644822/excel-interop-range-formatconditions-add-throws-missingmethodexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!