Valarenti
Valarenti

Reputation: 329

Aspose.Cells - get the rangename for a cell

I'm using aspose.cells in a .NET application. Let's say I have an excel workbook with three sheets named Sheet1, Sheet2, Sheet3. In Sheet1, cell A1 has been named "Apple" with global scope. In worksheets Sheet2 and Sheet3, cell A1 is named "Banana" (so it is not global.)

So in my VB.NET code I have a Cell. It seems like the Aspose name is just the letter-number. What I want is if I'm referencing the cell A1, a function that returns "Apple" if that cell is in SHeet1, and "Banana" if that cell is in Sheet2 or Sheet3.

It seems like this should be straightforward, but the only solution I've seen involves creating helper functions that work with the entire names collection?

Upvotes: 0

Views: 195

Answers (1)

Amjad Sahi
Amjad Sahi

Reputation: 1931

To get specific worksheet scoped named range, you need to get it with respect to its worksheet. For global (Workbook) named range, you can directly access it via its name. See the sample code for your reference:

e.g.

Sample code:

'Open the Excel file
Dim workbook As Workbook = New Workbook("g:\test2\Book1.xlsx")
'Get the worksheet collection
Dim worksheets As WorksheetCollection = workbook.Worksheets

'Getting the specified global named range
Dim namedRange As Range = worksheets.GetRangeByName("Apple")
Console.WriteLine("Named Range : " & namedRange.RefersTo)

'Getting the specified local named range
Dim namedRange2 As Range = worksheets.GetRangeByName("Sheet2!Banana")
Console.WriteLine("Named Range : " & namedRange2.RefersTo)

'Getting the specified local named range
Dim namedRange3 As Range = worksheets.GetRangeByName("Sheet3!Banana")
Console.WriteLine("Named Range : " & namedRange3.RefersTo)

....

Hope, this helps a bit.

You may also post your queries in the dedicated forum.

PS. I am working as Support developer/ Evangelist at Aspose.

Upvotes: 0

Related Questions