如何引用单元格作为DriveApp的文件或文件夹ID? [英] How to reference a cell as the file or folder id for DriveApp?

查看:48
本文介绍了如何引用单元格作为DriveApp的文件或文件夹ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用脚本功能,其中包含文档文件tmplate和Google云端硬盘文件夹位置的ID.我希望ID是动态的,基于用户通过Google表格中的单元格引用输入的信息.

I have an app script function that includes IDs for both a doc file tmplate and a Google Drive folder location. I want the ID to be dynamic based on a users input via a cell reference in a Google Sheet.

是否可以使用单元格引用来调用此值?

Is it possible to call this value using a cell reference?

示例:设置!B9 = Google文档模板ID

Example: Settings!B9 = Google Doc Template ID

//This value should be the id of your document template that we created in the last step
  const googleDocTemplate = DriveApp.getFileById('INSERT CELL REFERENCE');
  
  //This value should be the id of the folder where you want your completed documents stored
  const destinationFolder = DriveApp.getFolderById('INSERT CELL REFERENCE')

推荐答案

另一种选择是使用

Another option would be to use the getRange(a1Notation) function and pass Settings!B9 directly as a cell reference:

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const file_id = ss.getRange("Settings!B9").getValue(); // get value in "Settings!B9"
  const folder_id = ss.getRange("Settings!C9").getValue(); // get value in "Settings!C9"
  const googleDocTemplate = DriveApp.getFileById(file_id);
  const destinationFolder = DriveApp.getFolderById(folder_id)
}

这篇关于如何引用单元格作为DriveApp的文件或文件夹ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆