复制和授权后,Google脚本将停止工作

时间:2017-08-24 06:12:15

标签: google-sheets

制作完整版Google工作表的副本,以及随附的脚本;脚本本身在副本中不再起作用。 我通过授权它作为一个应用程序的步骤,但它似乎挂起我在副本上运行它。它在540多秒后超时。它似乎与DriveApp.createFolder有问题(exectution时间540秒)。然而,我没有改变脚本中的任何内容,在原始版本上工作正常。 这是脚本,我非常确定这里的一切都很好,它只是在你复制它的时候不想工作。我需要为团队中的每个人制作此表的副本,但我现在不能。

    function saveAsCSV() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  var date = SpreadsheetApp.getActiveSheet().getRange(3,2).getValue();
  var time = SpreadsheetApp.getActiveSheet().getRange(4,2).getValue();
  var site = SpreadsheetApp.getActiveSheet().getRange(2,2).getValue();
  // iterate through all sheets in the spreadsheet and rename them according to cell B2
  for( var j = 0 ; j < sheets.length; j++) {
    var sourceSheet = sheets[j];
    // get contents of cell B2
    var newSheetName = sourceSheet.getRange("B2").getValue();
    // rename sheet
    sourceSheet.setName(newSheetName);
  }
  // create a folder from the named SNOWSURVEYS with date
  var folder = DriveApp.createFolder('SNOWSURVEYS' + '_' + date + '_'+ site);
    // append ".csv" extension to the sheet name
    fileName = SpreadsheetApp.getActiveSheet().getName() + ".csv";
    // convert all available sheet data to csv format
    var csvFile = convertRangeToCsvFile_(fileName);
    // create a file in the Docs List with the given name and the csv data
    folder.createFile(fileName, csvFile);
    var folderID = folder.getId();
    var folderName = folder.getName();
    var ui = UiApp.createApplication().setTitle('Your files have are in your google drive in a folder called ' + folder);
    var p = ui.createVerticalPanel();
    ui.add(p);
    p.add(ui.createAnchor('Click here to go straight to your files ',folder.getUrl()));
    SpreadsheetApp.getActive().show(ui)
  }

Execution transcript printscreen

0 个答案:

没有答案