将if语句脚本添加到电子表格的新行 [英] Add if statement script to new rows of spreadsheet

查看:78
本文介绍了将if语句脚本添加到电子表格的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力在列的后面附加if语句,因为我的数据表每天都会添加行.我需要将if语句每24小时添加到加入电子表格的新行中.

I'm struggling to append an if-statement down a column because my data table adds rows each day. I need the if-statement to be added to the new rows that join the spreadsheet every 24 hours.

在表中,列C包含我的if语句引用的日期.

Within the table, column C contains a date that my if-statement is referencing.

我正在尝试在右侧(在Q列中)的一列中添加if语句,该语句将告诉我C列中的日期是在今天的日期之前还是之后.问题是我不确定如何为每天添加到表的增量行添加功能.以下是我所拥有的:

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. The problem is I'm not sure how to add the function for the incremental rows that are appended to the table each day. 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);
}

您可能可以告诉我我完全被卡住了,因为上面有几个错误.每天如何将if语句添加到Q列下的活动行?

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?

推荐答案

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)
}

这篇关于将if语句脚本添加到电子表格的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆