简体   繁体   English

从 appScript 和 google sheet 获取姓氏和电话号码

[英]get last name and phone number from appScript and google sheet

I have these two functions that take data from a google sheet and then send a whatsapp message.我有这两个函数,它们从谷歌表格中获取数据,然后发送一条 whatsapp 消息。 I can't modify the first function (getSheetData_) to take only the data from the last row.我无法修改第一个 function (getSheetData_) 以仅获取最后一行的数据。 I only have two columns (name and phone).我只有两列(姓名和电话)。 I have a trigger that launches the script on every change.我有一个触发器,可以在每次更改时启动脚本。

source: https://www.labnol.org/whatsapp-api-google-sheets-220520来源: https://www.labnol.org/whatsapp-api-google-sheets-220520

const getSheetData_ = () => {
  const [header, ...rows] = SpreadsheetApp.getActiveSheet().getDataRange().getDisplayValues();
  const data = [];
  rows.forEach((row) => {
    const recipient = { };
    header.forEach((title, column) => {
      recipient[title] = row[column];
    });
    data.push(recipient);
  });
  return data;
};

const main = () => {
  const data = getSheetData_();
    data.forEach((recipient) => {
      const status = sendMessage_({
        recipient_number: recipient["Phone Number"].replace(/[^\d]/g, ""),
        customer_name: recipient["Customer Name"]
      });
  });
};

Solution:解决方案:

 const getSheetData_ = () => { var sheet = SpreadsheetApp.getActiveSheet(); var lastRow = sheet.getRange(sheet.getLastRow(),1,1,2); const header = ['Customer Name', 'Phone Number']; const rows = lastRow.getDisplayValues(); const data = []; rows.forEach((row) => { const recipient = { }; header.forEach((title, column) => { recipient[title] = row[column]; }); data.push(recipient); }); return data; };

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

相关问题 复制到谷歌表格应用程序 - copyTo google sheet appscript AppScript Google Sheets:将结账表中的序列号匹配到主表,然后更新主表中的单元格 - AppScript Google Sheets: Match Serial #s from checkout sheet to the main sheet then update cells in main sheet 在 Google AppScript 中指定直到最后一列的范围 - Specifying range until last column in Google AppScript 从电话号码中删除最后一个连字符( - ) - Strip the last hyphen(-) from phone number Google Appscript:从 mysql 查询创建表并使用 appscript 绘制图表 - Google Appscript: Creating a table from a mysql query and charting it using appscript 根据谷歌表中的值清除行数据(特定数据)appscript - Clear Row Data Based on Value in Google Sheet ( Specific Data ) appscript 如何使用 appscript 阅读谷歌表格单元格中的评论或注释 - how to read comments or notes in a google sheet cell by using appscript 根据文件名从 Google Drive 获取图像 URL 到 Google Sheet - Get Image URL from Google Drive to Google Sheet based on file name 使用 Google Sheet 和 AppScript 向多个收件人发送 HTML 电子邮件 - Sending HTML email to multiple recipients using Google Sheet and AppScript Email 特定的 Google 表格为 PDF 使用 Appscript 的附件 - Email specific Google Sheet as PDF Attachment using Appscript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM