How To Prevent converting text string to number in office js

279 Views Asked by At

Ex: 101.01 is the string value but when data is added to the table it is converted to 101,01 (European number format) but in Excel it is displayed as text format, but the value is changed to (101.01 -> 101.01). How to prevent this in office js excel add-ins

1

There are 1 best solutions below

0
On

@cybernetic.nomad's suggestion is correct. Running this function in the Script Lab will indeed insert the value as a string, not as a number:

async function run() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const range = sheet.getRange("A1");
    range.values = [["'101.01"]];

    await context.sync();
  });
}

Note how I've inserted an apostrophe character at the beginning of the value string to be inserted.