We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get worksheet scoped named range

Hi,


I’ve edited an .xls file in Excel 2010 and added a worksheet scoped named range.
Trying to access it with book.Worksheets[1].Cells.Ranges I find this list to be empty.

This is the .NET version.

Am I doing it right?

Thanks
Michael

Hi Michael,

book.Worksheets returns a collection of worksheets. This collection is a zore-based index. If you have only one sheet in the Excel workbook, then you will get empty at index 1.

If it needs more explanation, please feel free to reach us with more detail also share your Excel file with us in order to get complete picture of the issue.

Thanks,

Hi Salman,


I am aware that worksheets is zero-based.
I have created a test file with named range scoped on the first sheet.
It is attached to this post.

Here is my code:

Workbook book = new Workbook(path);
Worksheet sheet = book.Worksheets[0];

System.Console.WriteLine(sheet.Name);

foreach( Range range in sheet.Cells.Ranges ){
System.Console.WriteLine(range.Name);
}


Thanks for your help.

Michael

Hi Salman,


Can you please confirm whether you are checking this problem?
We are currently evaluating this component and would like to know whether it can handle such operations.

Thanks,
Michael

Hi,

Well, your code (Worksheet.Cells.Ranges will extract the Workbook specific named ranges and not Worksheet specific named ranges) will work for Workbook(Global) named ranges. You may use Worksheets.GetNamedRanges() to extract both types of ranges.

See the sample code:

Range[] ranges = book.Worksheets.GetNamedRanges();

for (int i = 0; i < ranges.Length; i++)
{

MessageBox.Show(ranges[i].Name);
MessageBox.Show(ranges[i].Worksheet.Name);
}


For further reference on how to create both types of ranges, see the topic:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/create-workbook-global-worksheet-scoped-named-ranges.html



thank you.

Hi Amjad,


Thanks, it works!

Michael