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
Workbook.Worksheets.GetRangeByName doesn’t seem to return anything if there are more than one zone with the same name.
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,
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets;
//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");
Thank You & Best Regards,
That makes sense