Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets Google电子表格:从动态文件列表中自动引用单元格数据_Google Sheets_Spreadsheet - Fatal编程技术网

Google sheets Google电子表格:从动态文件列表中自动引用单元格数据

Google sheets Google电子表格:从动态文件列表中自动引用单元格数据,google-sheets,spreadsheet,Google Sheets,Spreadsheet,我有一个用谷歌电子表格创建的发票列表。现在,我想检索这些发票中的数据,创建另一个名为“All”的电子表格,其中包含每个发票的一行 Name Phone Street John 677 Main Mary 897 Niceday 有没有什么方法可以自动执行此操作,而不是逐个引用单元格 还有一个:想象一下,我添加了一个新的发票文件,我希望添加后,其中的姓名、电话和街道,会自动添加到“所有”文件中。是否可能?如果所有文件都位于单个驱动器文件夹中,则您可以从每个电子表格文件中检索所有数据,并

我有一个用谷歌电子表格创建的发票列表。现在,我想检索这些发票中的数据,创建另一个名为“All”的电子表格,其中包含每个发票的一行

Name Phone Street

John  677  Main
Mary  897  Niceday
有没有什么方法可以自动执行此操作,而不是逐个引用单元格


还有一个:想象一下,我添加了一个新的发票文件,我希望添加后,其中的姓名、电话和街道,会自动添加到“所有”文件中。是否可能?

如果所有文件都位于单个驱动器文件夹中,则您可以从每个电子表格文件中检索所有数据,并使用onOpen功能将其添加到主电子表格文件中

function onOpen(){
   // This active sheet.
   var mainSpreadsheet = SpreadsheetApp.getActiveSheet();
   // To store all of the invoice data
   var invoiceData = [];
   // Get all files inside a drive folder
   var files = DocsList.getFolderById("DRIVE FOLDER ID").getFiles();
   // For each file in the folder
   for (var i in files) {
      // Open the current spreadsheet in the interation
      var thisSpreadsheet = SpreadsheetApp.openById(files[i].getId());
      // Get the contents as an array and add it to invoiceData
      invoiceData.push(thisSpreadsheet.getDataRange().getValues());
   }
   // Clear all content in active sheet
   mainSpreadsheet.getDataRange.clearContent();
   // Get the write range from the number of values inside invoiceData
   var writeRange = mainSpreadsheet.getRange(1,1,invoiceData.length, invoiceData[0].length)
   // Add the data to the spreadsheet. 
   writeRange.setValues(invoiceData);
}
这是一个未经测试的示例。它将根据文件中的标题而有所不同,但它应该能帮助您开始