这是您可以尝试的“脚本解决方案”。有很多可能的方法,这是其中之一...
function testfindRow(){ ;// this function only to test the other one by giving it a parameter and using its result.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var otherSheet=ss.getSheets()[1];// assuming there is a second sheet to copy to
var datatocopy=findRow('Hello');
Logger.log(datatocopy)
if (datatocopy!=-1){
otherSheet.getRange(otherSheet.getLastRow()+1,1,1,datatocopy[0].length).setValues(datatocopy);
}
}
//
function findRow(item) { ;// the actual search function
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheets()[0];
var values = sheet.getDataRange().getValues();
for(cc =0; cc < values.length; ++cc) {
if(values[cc].toString().match(item)==item){break};// here you can eventually use string modifiers like toLowerCase() to allow for wider search criteria
}
Logger.log(cc);// the array index in which the result was found, cc+1 is the Row index
if (cc==values.length){return -1}
var resultArray=sheet.getRange(cc+1,1,1,values[cc].length).getValues()
return resultArray ;// the returned value is a 2 dimensions array to use with setValues()
}
根据您的评论,这是一个返回包含该项目的所有行的版本,我也必须更改错误捕获,但毕竟整个事情都非常简单。
function testfindRow(){ ;// this function only to test the other one by giving it a parameter and using its result.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var otherSheet=ss.getSheets()[1];// assuming there is a second sheet to copy to
var datatocopy=findRow('Hello');
if (datatocopy.length>0){
otherSheet.getRange(otherSheet.getLastRow()+1,1,datatocopy.length,datatocopy[0].length).setValues(datatocopy);
}
}
//
function findRow(item) { ;// the actual search function
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheets()[0];
var resultArray=new Array();
var values = sheet.getDataRange().getValues();
for(cc =0; cc < values.length; ++cc) {
if(values[cc].toString().match(item)==item){// here you can eventually use string modifiers like toLowerCase() to allow for wider search criteria
// or like this to search only in column D // if(values[cc][3].toString().match(item)==item){
resultArray.push(values[cc]);
};
}
Logger.log(resultArray);// the array of Rows in which the item was found,
return resultArray ;// the returned value is a 2 dimensions array to use with setValues()
}