简体   繁体   English

将 if 语句脚本添加到电子表格的新行

[英]Add if statement script to new rows of spreadsheet

I'm struggling to append an if-statement down a column because my data table adds rows each day.我正在努力 append 一个列中的 if 语句,因为我的数据表每天都会添加行。 I need the if-statement to be added to the new rows that join the spreadsheet every 24 hours.我需要每 24 小时将 if 语句添加到加入电子表格的新行中。

Within the table, column C contains a date that my if-statement is referencing.在表中,列 C 包含我的 if 语句引用的日期。

I'm trying to add the if-statement in a column off to the right (in column Q) that will tell me if the date in column C is before or after today's date.我正在尝试在右侧的列中添加 if 语句(在 Q 列中),它将告诉我 C 列中的日期是在今天的日期之前还是之后。 The problem is I'm not sure how to add the function for the incremental rows that are appended to the table each day.问题是我不确定如何为每天附加到表的增量行添加 function。 Below is what I have:以下是我所拥有的:

function AddFormula() {
  var spreadsheet = SpreadsheetApp.getActive();
  var column = spreadsheet.getRange('Q:Q').activate();
  var lastrow = 
  spreadsheet.getCurrentCell().setFormula('=if($C2<(today()),1,0)');
  spreadsheet.getActiveRange().autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
}

You may be able to tell I'm totally stuck because above has several errors.你可能会说我完全被卡住了,因为上面有几个错误。 How can I have my if statement added to the active rows down column Q on a daily basis?如何每天将我的 if 语句添加到 Q 列下方的活动行中?

Why not use an array formula in your top row?为什么不在第一行使用数组公式?

=ArrayFormula(if(C2:C < TODAY(),1,0))

To limit the range that the array formula is applied to you can use indirect()要限制应用数组公式的范围,可以使用indirect()

=ArrayFormula(if(indirect("C2:C"&counta(C2:C)+1,1) < TODAY(),1,0))
function AddFormula() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const srg=sh.getRange(1,17).setFormula('=if($C2<(today()),1,0)');
  const drg=sh.getRange(1,17,sh.getLastRow(),1);
  srg.autoFill(drg,SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES)
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM