“object”未包含“get_Range”的定义
来源:互联网 发布:cdh大数据平台 编辑:程序博客网 时间:2024/04/25 20:30
在VS2010中调用COM Interop DLL操作Excel通过get_Range去获取Range时,会发生Object does not contain a definition for get_Range的错误。其原因和解决方案:
Misha's explanation is correct - when using No PIA, methods returning object are treated as if they return dynamic in order to simulate the VBA semantics of COM Variants. Because the return value of sh.Cells is Object, sh.get_Range is dispatched dynamically, and the dynamic COM binder does not support the get_Range syntax exposed in C# before indexed properties were supported. We've tried to maintain backwards compatibility wherever possible when you turn on Embed Interop Types for a COM reference, but this is one place where some further tweaking is required.
The workaround you proposed will work - a cleaner workaround is the one Mike Rosenblum pointed out to use C# 4.0's new indexed properties syntax, which the dynamic COM binder does understand. You can then represent the operation with the following code:
Excel.Range r = sh.Range[sh.Cells[1, 1], sh.Cells[2, 2]];
See Also
Misha's explanation is correct - when using No PIA, methods returning object are treated as if they return dynamic in order to simulate the VBA semantics of COM Variants. Because the return value of sh.Cells is Object, sh.get_Range is dispatched dynamically, and the dynamic COM binder does not support the get_Range syntax exposed in C# before indexed properties were supported. We've tried to maintain backwards compatibility wherever possible when you turn on Embed Interop Types for a COM reference, but this is one place where some further tweaking is required.
The workaround you proposed will work - a cleaner workaround is the one Mike Rosenblum pointed out to use C# 4.0's new indexed properties syntax, which the dynamic COM binder does understand. You can then represent the operation with the following code:
Excel.Range r = sh.Range[sh.Cells[1, 1], sh.Cells[2, 2]];
See Also
get_Range method missing with embedded interop assembly
该问题的解决办法是:将下面的行1修改成行2的形式,这样就解决了。
行1: workSheet.get_Range(workSheet.Cells[2,1],workSheet.Cells[rowCount+1,colCount]).Value2=data;
行2:range = workSheet.Range[workSheet.Cells[2, 1], workSheet.Cells[rowCount + 1, colCount]];
range.Value = data;
0 0
- “object”未包含“get_Range”的定义
- object 未包含get_range的定义
- 写入EXCEL “object”未包含“get_Range”的定义
- Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包含“get_Range”的定义
- asp.net 将数据导入到excel中 出现 “object”未包含“get_Range”的定义
- C#将数据导入到excel中 出现 “object”未包含“get_Range”的定义报错
- VS2013中Winform导出Excel文件时报“object”未包含“get_Range”的定义解决方法
- C#将数据导入到excel中 出现 “object”未包含“get_Range”的定义
- E小cel 异常 “object”未包含“get_Range”的定义 解决方案
- asp.net 导出EXCEL 报错未包含 get_Range 的定义
- IFeatureBuffer.set_Value出现错误:“object”未包含“set_Value”的定义
- 记dynamic的一个小坑 -- RuntimeBinderException:“object”未包含“xxx”的定义
- Resources中未包含。。。的定义
- 在VS2010中调用COM Interop DLL操作Excel通过get_Range去获取Range时,会发生Object does not contain a definition for get_Range的错误。其原因和解决方案
- 根类Object包含的方法
- tair中对get/get_range接口的理解及为get_range添加命令行测试接口
- 多个类的定义相互包含
- 不包含“Contains”的定义
- Dell R720部署操作系统之总结篇
- 软件工程(软件计划)
- Hadoop MapReduce Next Generation - Capacity Scheduler
- linux host文件,主机名或者服务器名和ip地址之间的映射
- MongoDB 与JavaScript
- “object”未包含“get_Range”的定义
- android 拨打紧急号码,通话时开启免提功能实现
- sql中行列转换
- 微信公众平台推广攻略
- ios小笔记---实习了1个多月了 小记一下
- 新浪中一篇关于win32下双缓冲绘图
- syslog-ng学习心得之一
- INCREMENTAL AGGREGATION IN INFORMATICA
- 使用window.showModalDialog打开新窗口在IE上不兼容的问题