zoukankan      html  css  js  c++  java
  • VS2010的新特性:4.简化了对 Office API 对象的访问

    索引属性改进了在 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);

  • 相关阅读:
    python函数续
    模拟数据库查询操作
    文件处理
    字符编码
    python函数
    ACM-ICPC 2018 南京赛区网络预赛Skr
    bzoj3676: [Apio2014]回文串 pam
    Wannafly挑战赛23B游戏
    bzoj4804: 欧拉心算 欧拉筛
    bzoj3884: 上帝与集合的正确用法 扩展欧拉定理
  • 原文地址:https://www.cnblogs.com/letnet/p/1783554.html
Copyright © 2011-2022 走看看