Finding a range Name



My code opens a designer file and generates several hundred named ranges, using the API like:

Range range ;
range = w.Cells.CreateRange(startingRow, 2, rangeLength, 1) ;
range.Name = rangeName ;

Then later on, as I'm creating validation lists, I am using the range names, due to missing data on my side, not all ranges exist, so I want to check if the range name exists prior to using it (or the validation will fail when saving the spreadsheet). I tried both:

Range range = excel.Worksheets.GetRangeByName( rangeName );


Range[] allRanges = excel.Worksheets.GetNamedRanges() ;

Both approaches seem to only work on the range names that pre-existed in the designer file. Am I doing something wrong, or missing an API? As a workaround I am using an internally managed array, but expected the component to have some way of finding something I just defined programatically.



Hi Kris,

Yes, these two methods only return pre-defined ranges in the designer file. So you have to manage them by your own code.

I think your suggestion is great. Aspose.Excel will support to find range in all named ranges, whether in designer file or defined by code. Thanks for your patience.