如何使脚本将副本保存到特定文件夹



我正在使用下面的脚本来复制我的谷歌工作表(仅限值和格式(。 但是,此脚本将新文件放在我的主Google驱动器中,我希望将文件保存到存档文件夹中。 如何编辑脚本以执行此操作?

function copySheetValuesV4(){
    var sourceSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    var sourceSheets = sourceSpreadsheet.getSheets();
    var destination = SpreadsheetApp.create('03_'+sourceSpreadsheet.getName()+' _December 2017');
    for (var i = 0; i < sourceSheets.length; i++){
        var sourceSheet = sourceSheets[i];
        if (!sourceSheet.isSheetHidden()) {
            var sourceSheetName = sourceSheet.getSheetName();
            var sValues = sourceSheet.getDataRange().getValues();
            sourceSheet.copyTo(destination)
            var destinationSheet = destination.getSheetByName('Copy of '+sourceSheetName).setName(sourceSheetName);
            destinationSheet.getRange(1,1,sValues.length,sValues[0].length).setValues(sValues);// overwrite all formulas that the copyTo preserved */
        }
        destination.getSheetByName("sheet1").hideSheet() // Remove the default "sheet1" */
    }
}

使用 DriveApp.getFolderById(folder_id).addFile(DriveApp.getFileById(destination.getId())) .这将获取电子表格 ID,然后将电子表格添加到文件夹中。

最新更新