Excel的互操作:Range.FormatConditions.Add抛出的MissingMethodException [英] Excel Interop: Range.FormatConditions.Add throws MissingMethodException

查看:928
本文介绍了Excel的互操作:Range.FormatConditions.Add抛出的MissingMethodException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写它使用的Microsoft.Office.Interop.Excel组件出口从Excel US preadsheets /导入数据的应用程序。一切都进行得很顺利(除1基于索引和所有可选参数!),直到我试图用条件格式。当我打电话Range.FormatConditions.Add我得到的MissingMethodException告诉我,这样的方法并不存在。这发生在Vista和XP。

下面是的code产生异常的例子:

  // 1。添加引用的Microsoft.Office.Interop.Excel(版本11.0.0.0)
// 2。编译并运行以下code:

使用的Microsoft.Office.Interop.Excel;

类节目
{
    静态无效的主要(字串[] args)
    {
        应用程序=新的应用程序();
        簿簿= app.Workbooks [1];
        工作表工作表=(表)workbook.Worksheets [1];
        范围范围= worksheet.get_Range(A1,A5);
        FormatCondition条件= range.FormatConditions.Add(
            XlFormatConditionType.xlCellValue,
            XlFormatConditionOperator.xlBetween,
            100,
            200);
    }
}
 

解决方案

这可能是你一个很好的链接:<一href="http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/8a91d154-f766-427a-963c-16dfa39e154a/" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/8a91d154-f766-427a-963c-16dfa39e154a/

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

解决方案

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

这篇关于Excel的互操作:Range.FormatConditions.Add抛出的MissingMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆