asp.net 导出EXCEL 报错未包含 get_Range 的定义
来源:互联网 发布:2017网络红歌 编辑:程序博客网 时间:2024/04/25 16:14
上面程序运行报错信息
“object”未包含“get_Range”的定义
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包含“get_Range”的定义
源错误:
行 32: r1 = worksheet.Cells[1, 3];
行 33: r.Merge(r1);
行 34: ((Excel.Range)worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 3])).Merge(Missing.Value); //横向合并
行 35: r = worksheet.Cells[1, 1];
行 36: r.Value2 = "导出EXCEL测试一";
上面添加的是 Microsoft Excel 11.0 Object Library 引用 项目里BIN目录下都有
在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
get_Range method missing with embedded interop assembly
原帖
http://topic.csdn.net/u/20101116/17/889e344d-8ac0-4f6e-959e-c7364d0b097c.html
-----广告---
http://www.52soku.com
- asp.net 导出EXCEL 报错未包含 get_Range 的定义
- asp.net 将数据导入到excel中 出现 “object”未包含“get_Range”的定义
- VS2013中Winform导出Excel文件时报“object”未包含“get_Range”的定义解决方法
- 写入EXCEL “object”未包含“get_Range”的定义
- “object”未包含“get_Range”的定义
- object 未包含get_range的定义
- C#将数据导入到excel中 出现 “object”未包含“get_Range”的定义报错
- C#将数据导入到excel中 出现 “object”未包含“get_Range”的定义
- Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包含“get_Range”的定义
- E小cel 异常 “object”未包含“get_Range”的定义 解决方案
- asp.net导出excel
- asp.net导出Excel
- asp.net导出excel
- asp.net导出Excel
- Asp.net 导出Excel
- asp.net导出excel
- asp.net 导出excel
- asp.net 导出Excel
- Yahoo!团队实践分享:网站性能优化的34条黄金守则(转)
- 谈谈我对攻读计算机研究生的看法(转)
- 纹理分割
- windows ce EDB数据库研究浅谈--枚举所有表及结构
- StrutsPrepareAndExecuteFilte
- asp.net 导出EXCEL 报错未包含 get_Range 的定义
- GPS跟踪位置变化过程的代码
- 让你自己写的Android的Launcher成为系统中第一个启动的,也是唯一的Launcher
- 记一次保存UIWebView的缓存经历(二)
- ORACLE学习笔记:Chapter 01--Oracle Architectural Components
- 开源项目 nxcc , 可以试一下 code.google.com/p/nxcc/
- (1) WF快速入门
- Java I/O总结
- 计算机科学箴言集