google-apps-script - 在文件夹中按名称打开文件并获取范围 A:N 中的值
问题描述
我有一个 file1,我需要来自其他 file2 的一些值。file2 和他的文件夹的名称是已知的,也是 file2 的文件夹的 ID。
当我想使用 Google App Script 时,如何获取 A:N 范围内的值并将它们复制到 file1?
解决方案
首先获取文件的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();
现在您有了数组中所需的值。
打开电子表格并使用数组设置值(记住要匹配行数和列数)
推荐阅读
- javascript - 如何发布我的 vue npm 库以同时支持 Vue 2 和 Vue 3,
- java - 对我的括号的改进,重新对齐 Java 代码
- bitbucket - 在我的 Maven 包上运行 jgitflow start 时出现异常(org.eclipse.jgit.api.errors.TransportException)
- python - 有没有办法在同一轴上绘制多个累积直方图,其中数据集被标准化
- java - 将 CharArray 中某个字符后的八个字符添加到字符串
- javascript - 在 Node 中调用具有命名空间的 .dll 库的正确方法是什么?
- java - Java 声音采样器未完成获取缓冲区
- javascript - 为什么反应调用api这么多次加载页面?
- memory-management - 为什么 MIPS 使用 2 个指针来引用程序参数有什么理由吗?
- python - 调用变量是否比调用另一个函数参数中的函数更昂贵?