Google apps script 使用外部脚本在新创建的Google电子表格中编写
我已经建立了一个简短的脚本,从谷歌表单中获取输入,并创建了一个新的电子表格。但是当我试图在工作表中设置这些值时,什么也没有发生。不确定这是由于我的代码还是由于缺乏授权,因为这是一个新创建的文件。这是我的密码:Google apps script 使用外部脚本在新创建的Google电子表格中编写,google-apps-script,google-sheets,google-drive-api,Google Apps Script,Google Sheets,Google Drive Api,我已经建立了一个简短的脚本,从谷歌表单中获取输入,并创建了一个新的电子表格。但是当我试图在工作表中设置这些值时,什么也没有发生。不确定这是由于我的代码还是由于缺乏授权,因为这是一个新创建的文件。这是我的密码: var templates = DriveApp.getFilesByName('Template'); // get the files named Template (only one) var template = templates.next(); // get the f
var templates = DriveApp.getFilesByName('Template'); // get the files named Template (only one)
var template = templates.next(); // get the first files in the list
var newFile = template.makeCopy(name,newFolder); // Make a copy of the Template file and put it in NewFolder
var ss = SpreadsheetApp.open(newFile);
var sheet = ss.getSheets()[0];
sheet.getActiveRange('B1').setValue(name);
感谢您的帮助我认为在您的脚本中,
getActiveRange('B1')
出现了一个错误。因为类工作表的方法getActiveRange()
没有参数。我想这就是你的问题所在。在这种情况下,会出现类似的错误,参数(字符串)与SpreadsheetApp.Sheet.getActiveRange的方法签名不匹配。
。我认为,什么都没有发生的原因可能是,根据您的问题,脚本是由OnSubmit事件触发器运行的。在这种情况下,请修改如下
sheet.appendRow([, name]); // In this case, the value is append to the column "B".
发件人:
致:
- 当您像上面那样修改并再次运行时,
name
的值将被放入创建的电子表格第一个选项卡上的单元格“B2”
注:
- 如果要在脚本运行时附加值,请修改
sheet.getActiveRange('B1').setValue(名称)代码>如下所示
sheet.appendRow([, name]); // In this case, the value is append to the column "B".
参考资料:
sheet.appendRow([, name]); // In this case, the value is append to the column "B".