How to convert a relative (A1) reference to absolute ($A$1)? #1512
Replies: 3 comments
-
I'd use regexps: const relativeAddr = 'D42';
const sheetName = hfInstance.getSheetName(sheetId);
const colPart = relativeAddr.match(/[A-Z]+/)?.[0];
const rowPart = relativeAddr.match(/[0-9]+/)?.[0];
const absoluteAddr = `${sheetName}!$${colPart}$${rowPart}`;
console.log(absoluteAddr); |
Beta Was this translation helpful? Give feedback.
-
@sequba Thank you. I'll use something like this. I think this simple time saver would be great addition to the library in the future. |
Beta Was this translation helpful? Give feedback.
-
Hi @sequba ! Sorry to bother you again. just want to give some feedback. After creating what I thought was the correct address I was still getting an error from hyperformula/src/parser/CellAddress.ts Lines 136 to 138 in 469c9dd So although in the AST the reference type was "CELL_REFERENCE_ABSOLUTE" the function returned false. This wasn't intuitive either since I did provide a sheetID to I just want to suggest that either:
Thanks for all the hard work on the great library. I hope this feedback is useful. If you think any other contributors might find my experience useful please share it with them. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
To use addNamedExpression you must not use relative addresses or else you get "error: Relative addresses not allowed in named expressions.".
So, if I have a relative address, is there any function that I just haven't found yet to convert it to absolute?
I see functions to convert string addresses to SimpleCellAddress and vice versa, but
simpleCellAddressToString()
for example does not have any option likeabsolute:boolean
to get an absolute address with the dollar signs.Do I need to manually parse the string and build it, or does something already exist somewhere?
If I must manually convert, is there any advice on how I should do it? Regex matching alpha and numeric boundary?
Thank you for your time.
Beta Was this translation helpful? Give feedback.
All reactions