是否可以返回 Excel 2002 工作簿中所有工作表的所有范围的列表?

发布于 2024-08-29 17:06:54 字数 480 浏览 6 评论 0原文

我想从 Excel 2002(客户要求,无法更改)工作簿和其中包含的工作表中提取“特殊”数据。我已将范围分类到这个“特殊”数据类别中。我想获取工作簿中所有工作表中所有范围的列表。我感兴趣的属性是范围名称和范围地址。我已经在谷歌上搜索了一段时间,但没有找到任何相关的东西。

我假设 Excel 2002 API 会公开类似的内容:

ApplicationClass app = new ApplicationClass();
Workbook workbook = app.Workbooks.Open(@"c:\file.xls", ...);
Worksheet worksheet = workbook.Worksheets["sheet1"] as Worksheet;
Range[] ranges = worksheet.GetAllRanges();

或类似的内容。然而,我犯了可悲的错误。

Excel 2002 可以实现这一点吗?

I want to extract "special" data from an Excel 2002 (client requirement, cannot change) workbook and worksheets contained therein. I have classified ranges in this "special" data category. I would like to acquire a list of all ranges in, ideally, all worksheets in a workbook. The attributes I'm interested in are the range name, and the range address. I have been googling for a while now, and have not found anything relevant.

I was assuming the Excel 2002 API would expose something like this:

ApplicationClass app = new ApplicationClass();
Workbook workbook = app.Workbooks.Open(@"c:\file.xls", ...);
Worksheet worksheet = workbook.Worksheets["sheet1"] as Worksheet;
Range[] ranges = worksheet.GetAllRanges();

or something similar. However, I am sadly mistaken.

Is this possible with Excel 2002?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹梦到西洲 2024-09-05 17:06:54

如果您正在查找所有已命名的范围,您应该查看 Workbook.Names 集合。
Names 集合中的每个 Name 都有一个 RefersTo 属性,该属性提供 Name 引用的公式或范围引用。
(但请注意,名称可以是公式而不是范围引用)

Dim oNM 作为

ActiveWorkbook.Names 中每个 oNM 的名称
debug.print onNM.Refersto
下一个网管

If you are looking for all the ranges that are Named you should look at the Workbook.Names collection.
Each Name in the Names collection has a RefersTo property that gives the Formula or Range Reference that is referenced by the Name.
(But be aware that a Name can be a Formula rather than a Range Reference)

Dim oNM as Name

for each oNM in ActiveWorkbook.Names
debug.print oNM.Refersto
next oNM

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文