I’m trying to receive a name of a cell. Below is a VBA example to do this, so I’m looking for Aspose C# “translation” of this.
Sub test()
Sheet1.Range("Q3").Name = "Sheet1!Moretesting"
Sheet1.Range("Q3").Name.Comment = "I'm commenting here"
Debug.Print Range("Q3").Name.Name
End Sub
edit. I’ll edit this for clarification to here too. Specifically the line
Debug.Print Range(“Q3”).Name.Name
is the important one here. Adding a name is not a problem.
I think this works pretty much backwards. The point is specifically to receive the name, adding the name isn’t a problem. So the line
Debug.Print Range(“Q3”).Name.Name
is the one that’s the most important here, but that’s the one that is missing from your suggestion.
@artokilponen,
For printing debugging information, please visit the Name.FullText property.
The complete code as follows:
private void TestMethod(Worksheet sheet)
{
NameCollection names = sheet.Workbook.Worksheets.Names;
int index = names.Add("Sheet1!Moretesting");
Name name = names[index];
name.Comment = "I'm commenting here";
name.SetRefersTo("Sheet1!Q3", false, true);
Console.WriteLine(name.FullText);
}
By accessing the FullText property of the name object, you can obtain the content you want. At present, Aspose.Cells does not support obtaining the name object based on the range name of Name (such as “Q3” in the sample code). Do you need to add such an interface?
Just to get a closure on this, the way I solved this, is that I just keep a dictionary of the names I make and then pick them from there. Obviously this solution only works if I make the names by myself in the code.
Another, longer version would be to loop the name collection and inspect the “refersto” of each name and then return the matching one.