简体   繁体   English

火力地堡 | 谷歌表 | 应用脚本 | 每次触发函数时如何将值放在新行上?

[英]Firebase | Google Sheet | App Script | How do I put the value on new row everytime the function is triggered?

I have to extract the data from Firebase to the Google Sheet.我必须将数据从 Firebase 提取到 Google 表格。 I have managed to sync my Firebase data to the Google Sheet but I can't put it in a new row everytime the trigger is called in App Script.我已设法将我的 Firebase 数据同步到 Google 表格,但每次在 App 脚本中调用触发器时,我都无法将其放在新行中。

Here's my code in App Script:这是我在 App Script 中的代码:

function getAllData() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  var sheet = ss.getActiveSheet();

  var firebaseUrl = "firebase url";
  var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);

  var dataSet = [base.getData()];
  var rows = [], data;

  for (i = 0; i < dataSet.length; i++) {
    data = dataSet[i];
    var in_time = Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss");
    var in_date = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd");
    rows.push([data.Tank1, data.RandomTank1, data.RandomMain, in_time, in_date]);

  }
  a=2;
  dataRange = sheet.getRange(a, 1, rows.length, 5);
  dataRange.setValues(rows);
}

The output is this: enter image description here输出是这样的: enter image description here

And I want it to look like this and update the data in a new row: enter image description here我希望它看起来像这样并在新行中更新数据:在此处输入图像描述

EDIT:编辑:

Thank you very much @onit for solving this for me!非常感谢@onit 为我解决这个问题! It worked!有效!

Here's the screenshot of the output: enter image description here这是输出的屏幕截图:在此处输入图像描述

Try replacing the last 2 lines with: dataRange = sheet.getRange(sheet.getLastRow() + 1, 1, rows.length, rows[0].length).setValues(rows);尝试将最后两行替换为: dataRange = sheet.getRange(sheet.getLastRow() + 1, 1, rows.length, rows[0].length).setValues(rows);

References参考

getLastRow() 获取最后一行()

setValues() 设定值()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase | 谷歌表 | 应用脚本 | 如何将列中的数据而不是行中的数据从 Firebase 保存到 Google 表格? - Firebase | Google Sheet | App Script | How do I save the data in column instead of row from Firebase to Google Sheet? 有没有办法提高与 Firebase 连接的我的谷歌表格应用程序脚本的性能? - Is there anyway to increase performance of my google sheet app script connected with Firebase? 每次在 firebase 中添加 sha 密钥时,是否需要下载谷歌服务 json 文件? - Do I need to download google service json file everytime I add sha key in firebase? 如何模拟从 Firebase function 内部排队 Google Cloud 任务? - How do I emulate enqueuing a Google Cloud Task from inside a Firebase function? 通过 expo 在 firebase 中注册帐户的格式以及如何编写代码以在通过应用程序创建新用户时捕获错误 - Format for registration of account in firebase via expo and how do i code my code to catch errors when creating new user via app 如果我在 Firebase 上链接一个已经在 Google Play Store 上的应用程序,是否需要填写 SHA-1? - Do I need to fill SHA-1 if I am linking on Firebase an app that is already on Google Play Store? 当我尝试初始化 firebase 应用程序时,为什么 Google Cloud Functions 会抛出“配置 firebase.databaseURL 的无效值”错误? - Why is Google Cloud Functions throwing a "Invalid value for config firebase.databaseURL" error when I try to initialize a firebase app? 每次在 android 中添加新数据时,如何检测 Firebase 实时数据库中的变化并发送通知? - How to detect change in Firebase realtime database and send notification everytime a new data is added in android? Firebase:如何在应用检查中注册我的 Flutter 应用? - Firebase: How do I register my Flutter app in app check? 我是否需要 Firebase 项目才能使用 Firebase App Check? - Do I need a Firebase project to use Firebase App Check?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM