Concatenating strings in Google Apps Script

天大地大妈咪最大 提交于 2019-12-01 17:55:00

In your code you have written i&j that's not the syntax to concat in Google apps script. Instead you can simply use i + j. For looping you'll need to use any loop, like for, while, do-while.

Combining these suggestions, here is my final suggestion.

Try something like this [By using 'try' here I mean, simply don't copy-n-paste and use. Try to understand and write your own code, curated for your specific need. Maybe that way, we'll grow/learn more]

function myFunction() {
  var START_WEEK = 1; //Put your starting week count here
  var END_WEEK = 2; //Put your ending week count here
  var spreadSheet = SpreadsheetApp.getActiveSpreadsheet()
  var pre_name = "Week"
  var i;
  for (i = START_WEEK; i <= END_WEEK; i++) {
    try {
      spreadSheet.deleteSheet(spreadSheet.getSheetByName(pre_name + " " + i))
    } catch (exp) {
      //Maybe sheet with that name is not found
      Logger.log(exp.toString());
    }
  }
}

This code loop through all sheet whose name start with "Week " and then followed by week count, up till the end week count and if that's found it's deleting them.

Make sure you put in START_WEEK and END_WEEK properly.

Let me know if this doesn't work for you or if you have any query.

Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!