Created
August 5, 2023 16:50
-
-
Save palumbo/d81f9541a8ee0829420c97a2a55936c3 to your computer and use it in GitHub Desktop.
This Google Apps Script creates folders and files in Google Drive based on values in Google Sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction() { | |
// Spreadsheet Variables | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getActiveSheet(); | |
var lastRow = sheet.getLastRow(); | |
// Google Drive Variables | |
var rootFolder = DriveApp.getFolderById("1oqHxYeC8wC0ufJ8WPtq4WKfoJDqulppB"); | |
// Logger.log(lastRow); << 18 | |
for ( var i = 1; i < lastRow; i++ ) { | |
// create folder | |
let title = sheet.getRange(i,1).getValue(); | |
let description = sheet.getRange(i,7).getValue(); | |
if ( title != "title") { | |
var folderId = rootFolder.createFolder(title).getId(); | |
var folder = DriveApp.getFolderById(folderId); | |
// Logger.log('Folder Name: ' + title + ' Folder ID ' + folderId); | |
var docID = DocumentApp.create(title).getId(); | |
var document = DocumentApp.openById(docID); | |
var paragraph = document.getBody().appendParagraph(description); | |
DriveApp.getFileById(docID).moveTo(folder); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for shearing code