typescriptoffice-scripts

Write Office Script Formulas containing Quotes


I am trying to write an Excel office script formula to a cell. How do I write a formula with quotes to a cell?
This works: wsWa.getCell(WaRangeRowCount, 9).setFormula("= 1 + 1");

How can I write something like this =TEXT($E$18,"dddd"). I am unable to include the quotes using office script.


Solution

  • In JavaScript you may write strings using three different quote types

    let single = 'single-quoted';
    let double = "double-quoted";
    
    let backticks = `backticks`;
    

    So, if you want a string with " just use '-string or `-string

    (actually you need to escape " as \" , but what's the point if you can just use another string form)

    Check https://javascript.info/string for more info on JS strings