微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

向此脚本添加什么以使其在主文件夹下的驱动器中创建客户文件夹?

如何解决向此脚本添加什么以使其在主文件夹下的驱动器中创建客户文件夹?

我编写了脚本来复制客户并制作他们自己的工作表。现在我还想让它在名为 Customer Files 的主文件夹下为每个客户在 google drive 中创建一个文件夹。你能帮我吗?

function clonesheetsIter() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var mainSheet = ss.getSheetByName("Customer_Entry");
  var startRow = 6;
  var numRows = mainSheet.getLastRow();//obtains the last row in the sheet
  var setrgh = mainSheet
  var datarange = mainSheet.getRange(startRow,1,numRows,15); //rowStart,columnStart,row count,column count,the columncount needs to be large enough to encompass all your ancillary data
  var data = datarange.getValues();
  var iter = 0;
  var c0d = "B2";
  
  if (numRows >= 180){var maxIter = 180;}else{var maxIter = numRows;} //Setting maxIter to numrows or a predefined value,whichever is smaller
 
  for (i in data){
    if (iter != maxIter){ //making sure we haven't gone over the iteration limit
      var row = data[i];
      if (row[0] != ""){ //making sure the first cell in that row of data isn't empty to ensure we stop at the end of data and dont make blank sheets
        var newName = (row[0]);
        var checkExist = ss.getSheetByName(newName); //if the proposed sheetname doesnt exist,returns null,or sometimes sheet
        if (!checkExist) { //skip if it exists already
          if (checkExist !="Sheet"){ //skip if called sheet
            var row = data[i];            
            var newSheet = ss.getSheetByName('Customer_Info_Template').copyTo(ss); //make a copy of the template sheet
            SpreadsheetApp.flush(); //its rude not to flush
            newSheet.setName(newName); //set the name of the copied sheet
            ss.setActiveSheet(newSheet);// then set it as active
            newSheet.getRange(c0d).setValue(row[0]).setNote(mainSheet.getRange(startRow+(iter),1).getNote());
            
            /*
            
            Two-line sample of range protection which may be done while the sheets are created iteratively
            Additional disparate cells may be protected by duplicating the second line,or groups of cells may be protected by specifying a range in A1 notation,ie ("G2:K6")
            
            var sheet = ss.getSheetByName(newName);
            sheet.getRange("G2").protect().setWarningOnly(true);
            */
          }
        }
      }
      iter+=1; //iteration ++ at the end of the for loop
    }
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。