Free Support Forum - aspose.com

NamedRange - worksheet or workbook

Hi,

From the api, it gives the impression that a named range is a property
of a worksheet. However, from what I can tell of Excel it ought to be a
property of the workbook (e.g. ActiveWorkbook.Names collection in VBA),
although there does seem to be something called “worksheet-specific
name” - which is "all names beginning “Sheet1!” " according to
Microsoft.



Can you explain which names we get from the worksheets collection and
how they relate to the names as they might appear within Excel.



Thanks

Tim Pigden


Hi Tim,

Thanks for considering Aspose.

Well, Worksheets.Names property returns named ranges of cells. It actually represents the Names collection so you may get all the named ranges of cells in the worksheets

Following is the sample code, Suppose you have created some named ranges of cells in your spreadsheet template file. The code will return the first named range of cells in the collection and show its text or label in the message box.

Workbook wb = new Workbook();

wb.Open(@"d:\testbk.xls");

Worksheets worksheets = wb.Worksheets;

Names names = worksheets.Names;

Name name1 =names[0];

MessageBox.Show(name1.Text);

Regards

Amjad Sahi

Aspose Nanjing Team