简体   繁体   中英

I can not edit Google Apps Script after the code is complete

  • My problem is the editing ability in the google apps script, not the code itself. Thanks,
  • Explanation I can only edit Google Apps Script in a linear way. So for example if I've written a function and then I want to change a variable in it, I can't seem to be able to do that. To only do a minor change I have to completely write the code again line by line. Has happened every time I try to code in Google Apps Script. I also tested with debugger, seems to show no issues. Now, maybe there could be a specific error in this code, but it happens all the time with me, if I have to edit previous written code, I have to write it again step by step.
  • Here's the code in this case: First function works ok. Second function, to display images, I copied a code from stack overflow, and when I want to change column number in it, I can't edit that. just have to change 3 to 10, that's it.

    function myFunction() {
      SpreadsheetApp.getActive().getRange('Data!A1').setValue('=importdata("URL here")')
    }
    function convertToImage() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getActiveSheet();
      var range = sheet.getDataRange(); 
      // I was trying to change this number from 3 to 10, and it doesn't let me.
      var colnum = 3;             // assuming column C; change to another column number
      var cell;
      var values = range.getValues(); 
      for (var i=0; i<values.length; i++) {
        if (values[i][colnum-1]) {
          cell = range.getCell(i+1, colnum);
          cell.setFormula('=image("'+values[i][colnum-1]+'")')
        }
      } 
    }

I modified the code like this and saved it no problem

function convertToImage() {
  const ss = SpreadsheetApp.getActive;
  const sh = ss.getActiveSheet();
  const rg = sh.getDataRange();
  const col = 4;             
  const vs = rg.getValues();
  for (let i = 0; i < vs.length; i++) {
    if (vs[i][col - 1]) {
      rg.getCell(i + 1, col).setFormula('=image("' + vs[i][col - 1] + '")');
    }
  }
}

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