zoukankan      html  css  js  c++  java
  • VSTO选定单元格的三种方法

    一、使用Worksheet中的get_Range()方法。

                xlRange = (Excel.Range)(globals.MyAddin.Application.ActiveSheet as Excel.Worksheet).get_Range(
                   (globals.MyAddin.Application.ActiveSheet as Excel.Worksheet).Cells[row, col + 4],
                    (globals.MyAddin.Application.ActiveSheet as Excel.Worksheet).Cells[row, col + 4]);

    此方法没有重载,所以选定一个单元格时特别麻烦。

    二、直接使用Worksheet中的Cells属性,将Cells强制转换为Range对象。           

                xlRange = (globals.MyAddin.Application.ActiveSheet as Excel.Worksheet).Cells[row, col + 4] as Excel.Range;
                xlRange.Value2 = accountname;

    此种方法就比较简单了,用的方法还都是Range中的方法。

    三、直接给Worksheet中的Cells赋值。

               (globals.MyAddin.Application.ActiveSheet as Excel.Worksheet).Cells[row, col + 4] = accountname;

    由于Cells是一个object类型,因此,不能得到Cells相关的属性和方法,我没有找到基于这个对象的具体的类型,但通过ActiveCells可以看出,肯定有这个类型的。但是可以直接给对象赋值,不管是String也好,还是其它类型,都可以。

    我之前的项目都用的第一种方法,但第三种方法最简便直接。

  • 相关阅读:
    python mysql and ORM
    mysql-8.0.12-winx64 解压版安装(转)
    mysql装完计算机管理里面没mysql服务怎么解决(转)
    Python使用MySQL数据库(新)(转)
    Python之路,Day9
    python随笔2(列表的增删改查)
    python随笔1
    2018-05-23——PYTHON第三天
    2018-05-22——PYTHON第二天
    2018-05-21——python第一天
  • 原文地址:https://www.cnblogs.com/chuncn/p/1490239.html
Copyright © 2011-2022 走看看