Indexing with range names while using SpreadSheetGear's Advanced Cells API

眉间皱痕 提交于 2019-12-11 20:03:58

问题


I'm dealing with Excel file containing many sheets and even more formulas. I can reference all the 15K+ input cells with their range names, which is much nicer and readable than just using column-row indexes, like "AE2318".

Since the file is huge, I want to use SpreadsheetGear.Advanced.Cells interface to take advantage of any speedup possible. I noticed however that IValues interface can be indexed with 0-based row and column indexes.

How could I still use range names to refer to cells?

One thing I thought is to construct a dictionary, where I would store which ranges (cell with a given range name) resides on which sheet and which row/column. In Excel on the Formulas ribbon there's the Name Manager, which contains all this information, but how can I access that with SpreadSheetGear? The information is available from VBA.


回答1:


You can access Named Ranges via:

  1. IWorkbook.Names[...], which will include all Named Ranges for the entire workbook.
  2. IWorksheet.Names[...], which will include "worksheet-scoped" Named Ranges for a given worksheet.

These collections can be iterated over via a foreach loop which would return an IName object for each Named Range. You can also index into these collections via the Named Range's (string) name, or index within the collection. Once you have an IName object that represents a given Named Range, and assuming it actually refers to an underlying IRange (consider that Named Ranges could also refer to static values such as ="Hello World!"), you can use IName.RefersToRange to get that IRange object and any zero-based row/column indexes and row/column counts (IRange.Row/Column and RowCount/ColumnCount) for use in the "high performance" IValues interface.



来源:https://stackoverflow.com/questions/33602560/indexing-with-range-names-while-using-spreadsheetgears-advanced-cells-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!