Create a .txt file using the Excel Javascript API RRS feed

  • Question

  • I'm trying to create a .txt file using the excel javascript API and I have no idea how to get this done (I'm new to coding)

    The text I want to be inside the .txt file is already in a variable named "output".

    This is my try:

        function saveTxt(txt) {     
      var name = context.workbook.name
      var Path = Office.context.document.url.slice(0,-name.length)
      var saveFile = new File(Path + "data.txt");
      if (saveFile.exists){
      saveFile.encoding = "UTF8";
      saveFile.open("e", "TEXT", "????");

    When I run the code I get a "function expected" error. Would be nice to count with your help to solve that!

    The line throwing the "function expected" is the "var saveFile = new File(Path + "data.txt");"

    Btw, I don't know if it's relevant, but I'm coding directly in the ScriptLab excel add-in


    Friday, March 20, 2020 11:52 AM