gpt4 book ai didi

google-apps-script - 循环浏览谷歌表格以删除行 - 比较日期

转载 作者:行者123 更新时间:2023-12-04 02:11:26 24 4
gpt4 key购买 nike

代码需要删除日期早于当前日期的行。我没有收到任何语法错误,但我认为存在语义问题,因为代码不会以任何方式更改电子表格。

function checkDateValue(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var todaysDate = new Date().getDate();
var columnGCells = sheet.getRange("G2:G");
var columnG = columnGCells.getValues();

for (i = 1; i < sheet.height; i++) {
var endDate = new Date()
endDate = columnG[i];
if (todaysDate.getYear() >= endDate.getYear()){
if (todaysDate.getMonth() >= endDate.getMonth()){
if (todaysDate.getDay >= endDate.getDay()){
sheet.deleteRow(i);
}
}
}
}
};
checkDateValue();

最佳答案

代码可能看起来像这样:

function checkDateValue(e) {
var colG_values,columnGCells,columnNumber,endDate,i,lastRow,
sheet,startRow,todaysDate;

startRow = 2;//Get data starting in this row
columnNumber = 7://The column number to get the data from

sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
lastRow = sheet.getLastRow();

todaysDate = new Date().getDate();
//Logger.log('todaysDate: ' + todaysDate);

columnGCells = sheet.getRange(startRow,columnNumber,lastRow-1,1);
colG_values = columnGCells.getValues();

for (i = lastRow; i > 1; i--) {//Loop through values from last to first-
//Need to stop at row one-
endDate = colG_values[i];
endDate = new Date(endDate);

if (todaysDate.getYear() >= endDate.getYear()){
if (todaysDate.getMonth() >= endDate.getMonth()){
if (todaysDate.getDay >= endDate.getDay()){
sheet.deleteRow(i);//Delete this row
}
}
}
};
};

function runTest() {
checkDateValue();
};

关于google-apps-script - 循环浏览谷歌表格以删除行 - 比较日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37754080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com