Excel的互操作:Range.FormatConditions.Add抛出的MissingMethodException抛出、操作、Range、Excel

由网友(混吃等死)分享简介:我写它使用的Microsoft.Office.Interop.Excel组件出口从Excel US preadsheets /导入数据的应用程序。一切都进行得很顺利(除1基于索引和所有可选参数!),直到我试图用条件格式。当我打电话Range.FormatConditions.Add我得到的MissingMethodEx...

我写它使用的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);
    }
}
 

解决方案 区块链2020回顾 在金融 互联网和物流等的应用

这可能是你一个很好的链接: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/

阅读全文

相关推荐

最新文章