We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Problem with named cells

Hi,

I’d like to have two informations !
Actually, I have created in my excel file (in Excel not by using syncfusion) a defined name cell call “test”. The only way to get the text in this one is with the method “Range["test"].Text” and not thanks to the method : sheet.Names("CellName").Value. Is it normal ?
And secondly, I’d like to know if it’s possible to check if an defined named cell exist without crashing. Indeed, if the cell doesn’t exist in the Excel file, I’d like to know that by making a test. For the moment, I have always an exception and I don’t want to use a “try/catch”.

Thanks a lot!

1 Reply

LR Lokesh R Syncfusion Team July 28, 2010 05:56 AM UTC

Hi Benoit,

Thank you very much for your interest on Syncfusion products.

I have analyzed the two queries posted in your last update and given below the details in separate headings.

sheet.Names("CellName").Value:

The Value property associated with the INames will return only the A-1 style notation of the referred range which we represent in the macros without a "=" sign. If you have to retrieve a value of the named range you need to use the below code snippet instead of the above.

[C#]
sheet.Names["Test"].ReferToRange.Value;

Named cell exist without crashing:

you can read all the named cells by iterating the INames collections. I have given below the code snippet for the same.

[C#]
foreach (IName namedCell in wkBook.Names)
{
if (namedCell.Name == "Test")
{
System.Console.WriteLine(namedCell.RefersToRange.Value);
}
}

[VB]

For Each namedCell As IName In wkBook.Names
If namedCell.Name = "Test" Then
System.Console.WriteLine(namedCell.RefersToRange.Value)
End If
Next namedCell

Please, let us know if you need any clarifications.

Thanks,
Lokesh.

Loader.
Live Chat Icon For mobile
Up arrow icon