是否可以返回 Excel 2002 工作簿中所有工作表的所有范围的列表?
我想从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在查找所有已命名的范围,您应该查看 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