Thanks @ahsaniqbalsidiqui
However, that only works if the name already exists. Here is my code snippet.
Workbook wb = new Workbook("Book.xlsx");
Worksheet ws = wb.Worksheets[0];
Range range = ws.Cells.CreateRange(
firstRow: 1,
firstColumn: 1,
totalRows: 1,
totalColumns: 1);
MessageBox.Show(range.Address);
range.Address
always returns A1
whereas I may want $A1
or A$1
or $A$1
. If I name that range:
range.Name = "MyRange1";
Name name = wb.Worksheets.Names["MyRange1"];
MessageBox.Show(name.RefersTo);
name.RefersTo
does return =Sheet1!$A$1
. But that means I need to name a range every time I want to get absolute address and clean up the =
in front and also the extra sheet name.
Right now I’m manipulating the string myself:
string address = range.Address;
string column = new Regex(@"\$?[a-zA-Z]{1,3}").Match(address).Value;
address = address.Replace(column, $"${column}");
string row = new Regex(@"\$?[0-9]{1,7}").Match(address).Value;
address = address.Replace(row, $"${row}");
MessageBox.Show(address.Replace(range.Address, address));
to get $A$1
.
I’m wondering if Aspose has something else innate so I don’t have to do the above string manipulations.