2015-05-05 50 views
-2

我被要求將Google文件夾中的文件名和網址列表提供給Google電子表格。我試過應用一個腳本,但我不知道該怎麼做。如何將Google文件夾中的文件列表導入Google Spreadsheet?

你能幫忙嗎?

+0

選擇編輯 - >通過谷歌文檔 – HoangHieu

+0

你想拉*的文件(名稱和EX的鏈接列表*編輯。 )並將它們插入到Google電子表格中?在那種情況下顯示你到目前爲止的位置。 – user27636

+0

我想我應該使用「從Google文件夾中提取」一詞到Google表格「而不是」導入「。我想提取文件夾中的所有文檔(無論文件類型)並將它們導入到Google表格中 – Jonny

回答

2

沒有顯示工作,但可以。這會給你的文件名和他們的URL列表:

var SS = SpreadsheetApp.getActiveSpreadsheet(); 
 

 
/* 
 
The ONLY WAY to get the Id of a folder by right-clicking it and inspecting the link 
 
Example: link= 'https://drive.google.com/open?id=0Bw34txsxdsVDeuacnV2t0VHg1eGM&authuser=0' 
 
the id = '0Bw34txsxdsVDeuacnV2t0VHg1eGM' 
 
DOUBLE CHECK YOUR ID! 
 
*/ 
 
function getFileArray(folderId){ 
 
    var folder = DriveApp.getFolderById(folderId); 
 
    var files = folder.getFiles(); 
 
    var fileList = []; 
 
    
 
    //Loop though files and add names and urls to the array 
 
    while (files.hasNext()){ 
 
    var file = files.next(); 
 
    var fileName = file.getName();  
 
    var fileUrl = file.getUrl(); 
 
    fileList = fileList.concat([[fileName, fileUrl]]); 
 
    } 
 
    //See returned fileList in a log 
 
    //Logger.log(fileList) //Preview Returned Array  
 
    return fileList 
 
    
 
    
 
} 
 

 
    
 
//Prints any 2D array to a range that starts with the selected cell 
 
function printArrayToSelection(twoDimArr){ 
 
    var firstCell = SS.getActiveCell(); 
 
    var lastCell = firstCell.offset(twoDimArr.length - 1, twoDimArr[0].length - 1); 
 
    var destinationRange = SS.getActiveSheet().getRange(
 
    firstCell.getA1Notation() + ':' + lastCell.getA1Notation()); 
 
    destinationRange.setValues(twoDimArr); 
 
    
 
} 
 

 
//Print the actual data 
 
function printFileArray(){ 
 
    printArrayToSelection(getFileArray('yourforderid')); 
 
}

+0

非常感謝。我可以要求更多的幫助來實施它嗎?我沒有經驗,我不知道如何應用您提供的代碼。我使用腳本編輯器嗎?我是否必須編輯代碼以引用特定文件夾?我如何在Google Drive中運行它? Jonny – Jonny

+0

您需要將'folderID'放入printFileArray函數中。然後運行printFileArray()。 – user27636

+0

您需要從電子表格中調用腳本編輯器 - >將代碼粘貼到其中。如果您遇到問題,請先搜索谷歌。 – user27636

相關問題