如何替换已弃用的DocsList服务?

时间:2015-04-23 14:28:20

标签: google-apps-script google-sheets

自2015年4月20日起,DocsList服务“服务不再起作用”。我有这个函数这个函数使用了docsList服务:

/**
 * Duplicates a Google Apps doc
 *
 * @return a new document with a given name from the orignal
 **/

function createDuplicateDocument(sourceId, name) {
    var source = DocsList.getFileById(sourceId);
    var newFile = source.makeCopy(name);

  var targetFolder = DocsList.getFolderById(TARGET_FOLDER);
    newFile.addToFolder(targetFolder);
    return DocumentApp.openById(newFile.getId());
}

如何替换此DocsList函数中的createDuplicateDocument服务?

1 个答案:

答案 0 :(得分:5)

以下是新方式:

function createDuplicateDocument(sourceId, name) {
  //var source = DocsList.getFileById(sourceId);
  var source = DriveApp.getFileById(sourceId);

  var newFile = source.makeCopy(name);

  //var targetFolder = DocsList.getFolderById(TARGET_FOLDER);
  var targetFolder = DriveApp.getFolderById(TARGET_FOLDER);

  //newFile.addToFolder(targetFolder);
  targetFolder.addFile(newFile);

  return DocumentApp.openById(newFile.getId());
};