简体   繁体   English

每次运行时如何从Google表格中提取不同的值

[英]How to pull a different value from google sheets each time it runs

So I am trying to pull the value that is in the latest line of google sheets . 因此,我试图提取google sheets的最新行中的值。 Here is the part of the script that I am having trouble with. 这是我遇到麻烦的脚本部分。 This script is being written within google scripts. 该脚本是用Google脚本编写的。

When this script runs the confirmation email it sends has the value of var cell as undefined . 当此脚本运行确认电子邮件时,它发送的var单元格值为undefined 0 0

function formSubmitReply(e) {
  var userEmail = e.values[3];
  var sheet = SpreadsheetApp.getActiveSheet();
  var lastRow = sheet.getLastRow();
  // Set the status of the new ticket to 'New'.
  // Column F is the Status column
  sheet.getRange(lastRow, getColIndexByName("Status")).setValue("New");
  var supportEmail;

  // Calculate how many other 'New' tickets are ahead of this one
  var numNew = 0;
  for (var i = 2; i < lastRow; i++) {
    if (sheet.getRange(i, getColIndexByName("Status")).getValue() == "New") {
      numNew++;
    }
  }

  var range = sheet.getRange("B2:B100");

  var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues()
  Logger.log(values[0][0]);
  for(n=0;n<values[0].length;++n){
    var cell = values[n][1]
  }

The problem is here: 问题在这里:

for(n=0;n<values[0].length;++n){
    var cell = values[n][1]
  }

values[0].length is the number of columns while values[n][1] goes through rows. values [0] .length值[n] [1]通过行时的列数。

if you need a loop to go over the rows use this: 如果您需要循环遍历行,请使用以下命令:

for(n=0;n<values.length;++n){
        var cell = values[n][1]
      }

Otherwise if you have 10 columns and 50 rows, your loop will only go up to ten as values[0].length is 10 and you will pull data from: 否则,如果您有10列和50行,则循环将最多增加十个值[0]。length为10,您将从以下位置提取数据:

  1. A1 A1
  2. A2 A2
  3. A3 A3
  4. A4 A4

and etc until 等直到

  1. A10 A10

and then loop will stop. 然后循环将停止。

暂无
暂无

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

相关问题 从表单提交值后,如何将数据从 Google 表格提取到 Webapp? - How to pull the data from Google Sheets to Webapp after submitting a value from form? Google表格功能部分运行第二次 - Google Sheets Function Runs Partially a Second Time 如何为Google表格中单列中的每个值设置数字格式取决于值? - How to set number format for each value from single column in Google Sheets depends from value? 如何从谷歌表格中随机抽取一行并在 HTML 表格中使用它 - How to pull a random row from google sheets and use it in an HTML table 如何将文本从Google电子表格的多个单元格拉到网站中的每个不同的位置 <p> 标签? - How do I pull text from multiple cells in a google spreadsheet to website each in a different <p> tag? 如何通过使用 arrays 从 Google 表格中提取数据并格式化来优化 Apps 脚本代码? - How to optimise Apps Script code by using arrays to pull data from Google Sheets and format it? 如何使用 Tabletop.js 从 Google 表格中提取数据以绘制热图? - How to pull data from Google sheets using Tabletop.js for a plotly heatmap chart? 如何使阵列每次运行都能选择不同的选择? - How can I make my array choose different choices each time it runs? 使用Javascript的范围功能从Google表格中提取 - Using Javascript's range feature to pull from Google Sheets 如何从谷歌表格中的多个条件搜索中获取价值 - How to get value from multiple criteria search in google sheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM