0

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

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • An an apostrophe (`'`) in front of the string? – cybernetic.nomad Apr 06 '22 at 15:18
  • 1
    Try setting the range's [numberFormat](https://learn.microsoft.com/javascript/api/excel/excel.range?view=excel-js-preview#excel-excel-range-numberformat-member) to "Text" before you write the data to it. – Rick Kirkham Apr 06 '22 at 21:37

1 Answers1

0

@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.

Daniel Hume
  • 437
  • 4
  • 9