VS2010的新特性:4.简化了对 Office API 对象的访问
2010-07-23 10:54
316 查看
索引属性改进了在 C# 编程中使用具有参数的 COM 属性的方式,下面我们来看看Microsoft Office Excel的编程实例
在VS2008中访问 Range 属性,必须使用get_Range方法
var excelApp = new Excel.Application();
Excel.Range targetRange = excelApp.get_Range("A1", Type.Missing);
在VS2010中我们,使用索引属性
var excelApp = new Excel.Application();
Excel.Range targetRange = excelApp.Range["A1"]
这里还使用到了前面文章提到的可选参数,忽略了Type.Missing
我们在来看一下在VS2008中对AutoFormat的调用
excelApp.get_Range("A1", "B4").AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
该方法具有七个可选参数,调用起来非常繁琐。
在VS2010中通过命名话参数和可选参数,使得调用变得非常简单。
workSheet.Range["A1", "B3"].AutoFormat(Format:
Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2);
转载请注明:
自贡人才网,http://www.rcwqzg.com
金三维网络,http://www.jinsanwei.com
作者:Leek
在VS2008中访问 Range 属性,必须使用get_Range方法
var excelApp = new Excel.Application();
Excel.Range targetRange = excelApp.get_Range("A1", Type.Missing);
在VS2010中我们,使用索引属性
var excelApp = new Excel.Application();
Excel.Range targetRange = excelApp.Range["A1"]
这里还使用到了前面文章提到的可选参数,忽略了Type.Missing
我们在来看一下在VS2008中对AutoFormat的调用
excelApp.get_Range("A1", "B4").AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
该方法具有七个可选参数,调用起来非常繁琐。
在VS2010中通过命名话参数和可选参数,使得调用变得非常简单。
workSheet.Range["A1", "B3"].AutoFormat(Format:
Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2);
转载请注明:
自贡人才网,http://www.rcwqzg.com
金三维网络,http://www.jinsanwei.com
作者:Leek
相关文章推荐
- VS2010 C++ 学习笔记(三) 类和对象 访问限定符 String
- 如何:通过使用 Visual C# 2010 功能访问 Office 互操作对象(C# 编程指南)
- 20-常用对象API(集合框架-JDK5.0特性-ForEach循环) 21-常用对象API(集合框架-JDK5.0特性-函数可变参数). 1 2
- VS 2008 + .NET 3.5 - C# 3.0新特性之Automatic Properties(自动属性)、Object Initializers(对象初始化器)、Collection Initializers(集合初始化器)和Extension Methods(扩展方法)
- Wow, MS将在VS 2010中发布套件支持Eclipse、Unix、Linux和Mac访问TFS
- 探索Office 2010新特性
- VS 2010 WPF核心是哪些功能特性 ?
- 3、步步为营VS 2008 + .NET 3.5(3) - C# 3.0新特性之Automatic Properties(自动属性)、Object Initializers(对象初始化器)、Collection Initializers(集合初始化器)和Extension Methods(扩展方法)
- vs 2010 新特性(二)
- JDK8新特性☞访问对象字段和静态变量测试
- Chrome 66 新特性:CSS 类型对象模型,异步剪贴板 API,AudioWorklet,等
- 步步为营VS 2008 + .NET 3.5(3) - C# 3.0新特性之Automatic Properties(自动属性)、Object Initializers(对象初始化器)、Collection Initializers(集合初始化器)和Ext
- 【10.2移动新特性】Android 10.2 API简化,同样的功能,更少的代码!
- vs2010 office组件dll右键属性找不到”嵌入互操作类型“问题的解决
- 扩展Unity3d 组件方法,简化API使用 - C#特性之 Extension Method
- office 2010/2013激活工具及VS2013密钥
- Struts2系列:(5)与Servlet API解耦(Servlet相关对象访问)
- VS2010:“error C2712: 无法在要求对象展开的函数中使用 __try”
- 基于 VS 2010 阐述C# 4个特性
- MOSS 2010:Visual Studio 2010开发体验(17)——在Silverlight应用程序中访问客户端对象模型