0

I am using office JS to create a Excel Web Addin. I want to get the address of a cell in $A$1 form.

Right now I am using the address property of Excel.Range which gives the address like Sheet1!A1. How do I fetch it as Sheet1!$A$1?

Following is the code I use to load address property.

var activeCell = context.workbook.getActiveCell();
activeCell.load("address");

1 Answers1

0

You can use a regular expression to add the dollar signs before the column letters and row number.

Here's something that I think should work. Here $1 matches Sheet1!, $2 matches the column letters, $3 matches the row numbers, and $$ is to put a literal dollar sign in the result.

var res = str.replace(/(.*\!)(\D+)(\d+)/g, "$1$$$2$$$3");
adamk
  • 114
  • 1