我建立了一个电子表格来跟踪任务,项目,调查或事件或事件的进展,并包含了本文中的代码:
Automatically move data from one sheet to another in google docs
但是我也希望能够将插入到正在从Sheet1(活动)移动到Sheet2(归档)的单元格上的注释或笔记转移。
第1列设置为指示截止日期或完成日期-第2&3列为下拉菜单,因此我可以从已存档的信息中提取一些统计信息-列4-12设置为日期验证以跟踪进度或发展情况,并且包括详细信息插入的评论或注释。
这就是我所拥有的:
function onEdit(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName('ACTIVE');
var sheet2 = ss.getSheetByName('Archive');
var dateColumn = "1";
var array = []
var range = sheet1.getRange(1, 1, sheet1.getLastRow(), dateColumn);
for (var i = 2; i <= sheet1.getLastRow(); i++) //i iterates from 2 as you say R1 is header
{
if(isValidDate(range.getCell(i, dateColumn).getValue()) == true) //checking if any values on column16 is valid date
{
data = sheet1.getRange(i, 1, 1, 12).getValues(); //Getting the range values of particular row where C16 is date
for (var j = 0; j < 12; j++) //Adding the row in array
{
array.push(data[0][j]);
}
}
if(array.length > 0)
{
sheet2.appendRow(array); //Appending the row in sheet2
array = [];
sheet1.deleteRow(i); //deleting the row in sheet as you said you want to move, if you copy remove this and next line
i=i-1; //managing i value after deleting a row.
}
}
}
function isValidDate(d) {
if ( Object.prototype.toString.call(d) !== "[object Date]" )
return false;
return !isNaN(d.getTime());
}
让我知道是否可行。 谢谢