简体   繁体   中英

Is it possible to insert a Google Apps Script array value into a Sheet cell as plain text?

Put simply, I am working in Google Apps script, and I have an array value. I want to insert the array value into a sheet cell and the end result being the cell is set to plain text.

Everything about my code works, but this line refuses to result in a plain text output:

function minimal()
{ 
   const allFormResponses = fetchFormResponses();  //loads numbers from form output into a 2D array
   var sheet = SpreadsheetApp.getActive().getSheetByName("All");  
   var lastRow = sheet.getLastRow()+1;
   for(var d = 0; d < allFormResponses.length; d++) 
   {
      var lastRow = sheet.getLastRow()+1;
      for (var e = 0, col = 1; e < allFormResponses[d].length; e++, col++)
      {
         sheet.getRange(lastRow,col).setValue(JSON.stringify(allFormResponses[d][e].itemResponse.toString())).setNumberFormat("@");     
      }
   } 
}

I have also tried just formatting the entire column after each value is added and that doesn't work either.

Feeling stumped and I feel like it's probably something dumb I am missing.

Replace

sheet.getRange(lastRow,col).setValue(allFormResponses[d][e].itemResponse).setNumberFormat("@");     

by

sheet.getRange(lastRow,col).setValue(`'${allFormResponses[d][e].itemResponse}`);     

Related

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM