首页 > 解决方案 > 在文件夹中按名称打开文件并获取范围 A:N 中的值

问题描述

我有一个 file1,我需要来自其他 file2 的一些值。file2 和他的文件夹的名称是已知的,也是 file2 的文件夹的 ID。

当我想使用 Google App Script 时,如何获取 A:N 范围内的值并将它们复制到 file1?

标签: google-apps-script

解决方案


首先获取文件的ID

 myFolder = DriveApp.getFolderById('Put_The_Folder_ID_Here');

  allFiles = myFolder.getFilesByName(myFileName);

  while (allFiles.hasNext()) {//If there is another element in the iterator
    thisFile = allFiles.next();
    idoffile = thisFile.getId();}


然后使用ID打开文件

  var hisss=SpreadsheetApp.openById(idoffile);
  var hissht=hisss.getSheetByName("History") ;//sheet name
  var hislr=hissht.getLastRow()
  var vA =hissht.getRange("A:D").getValues();


现在您有了数组中所需的值。

打开电子表格并使用数组设置值(记住要匹配行数和列数)


推荐阅读