首页 > 解决方案 > 使用脚本从 Google 表单写入 Google 表格

问题描述

所以我有一个谷歌表单,我正在使用脚本处理表单中的数据,我最终想将这些数据填充到电子表格中。我已经测试了我的代码并且记录器正在打印表单本身中的所有数据,但我的谷歌表仍然是空的。我怀疑我使用错误的代码写入工作表,但我不确定。我浏览了 Sheets API,它说我可以使用写入工作表appendRow,并且可以选择使用哪个工作表写入openById(),但这些似乎不起作用。我真的很感激任何见解!

这是我现在可以写入电子表格的代码,但它不起作用。

var array1 = [id, score];  // these are 2 variables that were initialized previously 
array1 = array1.concat(array2);  
// array2 is another array that I've initialized previously which works fine
// (I've tested both of these arrays in the Logger and it prints correctly)  
var ss=SpreadsheetApp.openById(‘SSID’); 
var sheet = ss.getSheetByName("Name");
sheet.appendRow(array1);

标签: google-apps-scriptgoogle-apps-script-editor

解决方案


所以在玩了一段时间之后,我意识到修复方法是简单地删除 onFormSubmit 触发器,然后再次运行它。不知道为什么要修复它,但我假设它没有准确同步/更新。感谢所有的帮助!


推荐阅读