我试图遍历我的工作表中的行,根据F列中的日期删除某些行。我在第28行显示语法错误。我不确定是什么&# 39; s触发这个,因为代码看起来很好。任何意见,将不胜感激。
function dateReduce() {
var ss = SpreadsheetApp.openById('1yl599Ff7d1aaSTKpHAeHW5wswiDOzNegrKxS1Z1SquY');
var sheet = ss.getSheetByName("worksheet");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
var range = sheet.getRange(2, 6, 1374);
var values = range.getValues(); // getValues() results in a javascript array as opposed to a google script array
var numRows = range.getNumRows();
var endDate;
for (var i = 1; i <= numRows; i++) {
endDate = new Date(values[i][5]);
if (yyyy > endDate.getFullYear()) {
sheet.deleteRow(i);
};
else if (yyyy === endDate.getFullYear()) {
if ( mm > (endDate.getMonth()+1)) {
sheet.deleteRow(i);
};
};
else if ((mm === endDate.getMonth()+1) && (yyyy == endDate.getFullYear())) {
if (dd > endDate.getDate()) {
sheet.deleteRow(i);
};
};
};
};
答案 0 :(得分:0)
您需要在所有结束花括号(&#34;}&#34;)之后删除分号。除非涉及任务,否则你不需要在花括号后加分号。
function dateReduce() {
var ss = SpreadsheetApp.openById('1yl599Ff7d1aaSTKpHAeHW5wswiDOzNegrKxS1Z1SquY');
var sheet = ss.getSheetByName("worksheet");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
var range = sheet.getRange(2, 6, 1374);
var values = range.getValues(); // getValues() results in a javascript array as opposed to a google script array
var numRows = range.getNumRows();
var endDate;
for (var i = 1; i <= numRows; i++) {
endDate = new Date(values[i][5]);
if (yyyy > endDate.getFullYear()) {
sheet.deleteRow(i);
} else if (yyyy === endDate.getFullYear()) {
if (mm > (endDate.getMonth() + 1)) {
sheet.deleteRow(i);
}
} else if ((mm === endDate.getMonth() + 1) && (yyyy == endDate.getFullYear())) {
if (dd > endDate.getDate()) {
sheet.deleteRow(i);
}
}
}
}