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

Free Support Forum - aspose.com

Identify Names Range with the same name but different scopes

Hi,

In my workbook I have 2 worksheets, each containing one range which have the same name.

When defining a range, Excel let you specify the scope, whereas it is workbook or worksheet.

However Aspose.Cells doesn’t seem to differentiate them



I didn’t find any mention of such situation in this article



http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/named-ranges.html



Workbook.Worksheets.GetRangeByName doesn’t seem to return anything if there are more than one zone with the same name.



Thanks

Emmanuel

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, in case of sheet specific named ranges, you can get the range by using the same method

workbook.Worksheets.GetRangeByName("Sheet1!TestRange"), but you have to make sure that when the sheet specific range is created; it should also use the sheet name as prefix. . This means the global or workbook level ranges will come with out any sheet prefix and worksheet specific should be declared and then retrieved with worksheet name prefix.

Please see the following sample code,

Sample Code:

Workbook workbook = new Workbook();

Worksheet sheet = workbook.Worksheets[0];

//Create a named range

Range range = sheet.Cells.CreateRange("B1", "E5");

//Set the name of the named range

range.Name = sheet.Name + "!" + "TestRange";

//Get the sheet specific range and assign to range 2

Range range2 = workbook.Worksheets.GetRangeByName(sheet.Name + "!" + "TestRange");

workbook.Save("c:\\Ranges.xls");


Thank You & Best Regards,

That makes sense

Thank you

Emmanuel