Rumah > Soal Jawab > teks badan
Sebagai seorang pemula, saya menulis skrip untuk mengisi semua folder Google Drive saya ke dalam Helaian Google. Walaupun skrip berfungsi, saya terserempak dengan 错误:超过最大执行时间
dan senarai hasil folder saya belum lengkap.
Saya tidak dapat mengetahui cara mengendalikan/membetulkan tamat masa pelaksanaan. Saya telah mencari berbilang sumber tetapi tidak menemui apa-apa yang boleh membantu saya mempercepatkan skrip saya.
Jangkaan saya ialah skrip akan dilaksanakan dengan sangat pantas dan senarai "kemungkinan" beribu-ribu folder akan diisi paling lama dalam 1 minit.
function generateFolderList() { var rootFolder = DriveApp.getRootFolder(); var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var sheetName = Utilities.formatDate(new Date(), "GMT+1", "yyyy-MM-dd HH:mm:ss"); var newSheet = spreadsheet.insertSheet(sheetName); newSheet.getRange("A1:N1").setValues([["structure_level", "parent_folder", "folder_name", "folder_description", "folder_id", "folder_url", "owner_email", "sharing_access", "sharing_permissions", "mime_type", "starred_status", "trashed_status", "date_created", "last_updated"]]); listFolders(rootFolder, "", newSheet, 1); } function listFolders(folder, parentName, sheet, level) { var folderName = folder.getName(); var description = folder.getDescription(); var folderId = folder.getId(); var url = folder.getUrl(); var owner = folder.getOwner().getEmail(); var sharingAccess = folder.getSharingAccess(); var sharingPermission = folder.getSharingPermission(); var mimeType = "folder"; var starred = folder.isStarred(); var trashed = folder.isTrashed(); var dateCreated = folder.getDateCreated(); var lastUpdated = folder.getLastUpdated(); var rowData = [level, parentName, folderName, description, folderId, url, owner, sharingAccess, sharingPermission, mimeType, starred, trashed, dateCreated, lastUpdated]; sheet.appendRow(rowData); var subFolders = folder.getFolders(); level++; while (subFolders.hasNext()) { var subFolder = subFolders.next(); listFolders(subFolder, folderName, sheet, level); } }
Helaian Google dengan Skrip Apl ada di sini.
P粉7757887232023-09-08 00:48:56
Skrip aplikasi anda menulis pada hamparan apabila setiap folder atau subfolder muncul. Sebaliknya, anda harus mengumpul maklumat ke dalam tatasusunan dan kemudian menulis keseluruhan tatasusunan ke hamparan. Cuba ini, walaupun pada mulanya beberapa nilai sel adalah objek dan bukannya rentetan, jadi ia tidak akan berfungsi sehingga anda memutuskan sifat objek tersebut yang ingin anda tangkap. Saya baru guna toString()
.
function generateFolderList() { var rootFolder = DriveApp.getRootFolder(); var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var sheetName = Utilities.formatDate(new Date(), "GMT+1", "yyyy-MM-dd HH:mm:ss"); var newSheet = spreadsheet.insertSheet(sheetName); // 注意我创建了一个名为folders的数组,并将其传递给listFolders,而不是newSheet let folders = [["structure_level", "parent_folder", "folder_name", "folder_description", "folder_id", "folder_url", "owner_email", "sharing_access", "sharing_permissions", "mime_type", "starred_status", "trashed_status", "date_created", "last_updated"]]; listFolders(rootFolder, "", folders, 1); // 完成后复制到电子表格 newSheet.getRange(1,1,folders.length,folders[0].length.setValues(folders); } function listFolders(folder, parentName, folders, level) { var folderName = folder.getName(); var description = folder.getDescription(); var folderId = folder.getId(); var url = folder.getUrl(); var owner = folder.getOwner().getEmail(); var sharingAccess = folder.getSharingAccess().toString(); var sharingPermission = folder.getSharingPermission().toString(); var mimeType = "folder"; var starred = folder.isStarred(); var trashed = folder.isTrashed(); var dateCreated = folder.getDateCreated(); var lastUpdated = folder.getLastUpdated(); folders.push([level, parentName, folderName, description, folderId, url, owner, sharingAccess, sharingPermission, mimeType, starred, trashed, dateCreated, lastUpdated]); var subFolders = folder.getFolders(); level++; while (subFolders.hasNext()) { var subFolder = subFolders.next(); listFolders(subFolder, folderName, folders, level); } }
Rujukan