Excel range.Rows属性的作用是什么? [英] What does the Excel range.Rows property really do?

查看:308
本文介绍了Excel range.Rows属性的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在为旧版Excel-VBA应用程序完成一个附加项目,而我又一次遇到了神秘的range.Rows(?)和worksheet.Rows属性的难题.

OK, I am finishing up an add-on project for a legacy Excel-VBA application, and I have once again run up against the conundrum of the mysterious range.Rows (?) and worksheet.Rows properties.

有人知道这些属性的真正作用以及应该提供给我什么? (注意:所有这些可能也适用于相应的*.Columns属性.)

Does anyone know what these properties really do and what they are supposed to provide to me? (Note: all of this probably applies to the corresponding *.Columns properties also).

我真正想要 能够使用它的是返回一定范围的行,如下所示:

What I would really like to be able to use it for is to return a range of rows, like this:

   SET rng = wks.Rows(iStartRow, iEndRow)

但是,即使Intellisense显示了两个参数,我也无法做到这一点.相反,我必须使用其他两种或三种(非常模糊)的技术之一.

But I have never been able to get it to do that, even though the Intellisense shows two arguments for it. Instead I have to use one of the two or three other (very kludgy) techniques.

该帮助非常无用(通常对于Office VBA而言),并且无论我添加了多少其他术语,都对谷歌浏览行"都没有太大帮助.

The help is very unhelpful (typically so for Office VBA), and googling for "Rows" is not very useful, no matter how many other terms I add to it.

我唯一能够使用的方法是1)返回一行作为范围(rng.Rows(i))和2)返回该范围内的行数(rng.Rows.Count).是吗真的没有其他好处吗?

The only things that I have been able to use it for are 1) return a single row as a range ( rng.Rows(i) ) and 2) return a count of the rows in a range ( rng.Rows.Count ). Is that it? Is there really nothing else that it's good for?

说明:我知道它会返回一个范围,并且还有其他方法可以获取一定范围的行.我要的是专门从.Rows()中获得什么,而我们还没有从.Cells().Range()中得到什么?我知道的两件事是:1)一种更简单的方法来返回单个行的范围,以及2)一种计算范围内的行数的方法.

Clarification: I know that it returns a range and that there are other ways to get a range of rows. What I am asking for is specifically what do we get from .Rows() that we do not already get from .Cells() and .Range()? The two things that I know are 1) an easier way to return a range of a single row and 2) a way to count the number of rows in a range.

还有别的吗?

推荐答案

Range.RowsRange.Columns返回基本相同的Range,除了新Range具有用于表示行或列的标志之外.对于某些Excel属性(例如Range.Count和Range.Hidden)以及某些方法(例如Range.AutoFit():

Range.Rows and Range.Columns return essentially the same Range except for the fact that the new Range has a flag which indicates that it represents Rows or Columns. This is necessary for some Excel properties such as Range.Count and Range.Hidden and for some methods such as Range.AutoFit():

  • Range.Rows.Count返回范围中的行数.
  • Range.Columns.Count返回范围中的列数.
  • Range.Rows.AutoFit()自动调整范围中的行.
  • Range.Columns.AutoFit()自动调整范围中的列.
  • Range.Rows.Count returns the number of rows in Range.
  • Range.Columns.Count returns the number of columns in Range.
  • Range.Rows.AutoFit() autofits the rows in Range.
  • Range.Columns.AutoFit() autofits the columns in Range.

您可能会发现Range.EntireRowRange.EntireColumn很有用,尽管它们仍不是您要寻找的.对于所表示的范围,它们返回EntireRow的所有可能列和EntireColumn的所有可能行.

You might find that Range.EntireRow and Range.EntireColumn are useful, although they still are not exactly what you are looking for. They return all possible columns for EntireRow and all possible rows for EntireColumn for the represented range.

我知道这一点是因为 SpreadsheetGear for .NET 附带了.NET API,该API与Excel的API非常相似. SpreadsheetGear API为IRange索引器提供了几种强类型的重载,包括您可能希望Excel具有的重载:

I know this because SpreadsheetGear for .NET comes with .NET APIs which are very similar to Excel's APIs. The SpreadsheetGear API comes with several strongly typed overloads to the IRange indexer including the one you probably wish Excel had:

  • IRange this[int row1, int column1, int row2, int column2];

免责声明:我拥有SpreadsheetGear LLC

Disclaimer: I own SpreadsheetGear LLC

这篇关于Excel range.Rows属性的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆