I want to create a function to save a spreadsheet to a folder. I'm almost there, I think I just need to adjust the synthax of the createFile
class.
Here is my code:
const spreadsheet2 = SpreadsheetApp.getActiveSpreadsheet();
var folder2 = DriveApp.getFoldersById("my_folder_id").next();
var filename2 = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("B97").getValue();
folder2.createFile([I think here is my missing command].setName(filename2));
Could someone finish it?
getActiveSheet().getRange("B97").getValue()
.If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
DriveApp.getFoldersById("my_folder_id").next()
, there is no method of getFoldersById
. When you want to use the folder ID, please use DriveApp.getFolderById(folderId)
.createFile()
. In your case, in order to copy the active Spreadsheet, you can use makeCopy()
.When above points are reflected to your script, it becomes as follows.
var folderId = "###"; // Please set the folder ID you want to put the copied Spreadsheet.
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var filename2 = spreadsheet.getActiveSheet().getRange("B97").getValue();
var folder = DriveApp.getFolderById(folderId);
DriveApp.getFileById(spreadsheet.getId()).makeCopy(filename2, folder);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.