Hi there,
I am using Aspose.Cells v 23.5.
I need to store and manage several ranges (e.g. “A1:B5”) in one named range (e.g. ‘my_named_range’)
What is the best way for adding/removing ranges to/from a named range?
Thanks in advanced,
Shlomi
Hi there,
I am using Aspose.Cells v 23.5.
I need to store and manage several ranges (e.g. “A1:B5”) in one named range (e.g. ‘my_named_range’)
What is the best way for adding/removing ranges to/from a named range?
Thanks in advanced,
Shlomi
@shlomi.z
Please check the document:
And you can use NameCollection.Remove method to remove a named range:
workBook.Worksheets.Names.Remove("my_namedRange");
If the named range is refered by formulas, it can not be removed , we only can set the refer of the named range as null.
Also, see the simplest example code on how to store multiple ranges in a named range.
e.g.
Sample code:
// Instantiating Workbook object
//Load an Excel file
Workbook workbook = new Workbook("Book1.xlsx");
// Adding a Name to store multiple ranges
int index = workbook.Worksheets.Names.Add("my_named_range");
Name name = workbook.Worksheets.Names[index];
// Creating a non sequence range of cells
name.RefersTo = "=Sheet1!$A$1:$B$5,Sheet1!$E$5:$G$8";
// Save the workbook
workbook.Save("out1.xlsx");
Hope, this helps a bit.