我下面的脚本可以满足我的需要,除了结尾删除行之外。我需要的是将它从Sheet1复制并粘贴到Sheet2,并清除sheet1中除A列之外的行。
function copyrange() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1'); //source sheet
var testrange = sheet.getRange('D:D');
var testvalue = (testrange.getValues());
var csh = ss.getSheetByName('Sheet2'); //destination sheet
var data = [];
var j =[];
//Condition check in D:D; If true copy the same row to data array
for (i=0; i<testvalue.length;i++) {
if ( testvalue[i] == 'x') {
data.push.apply(data,sheet.getRange(i+1,1,1,11).getValues());
//Copy matched ROW numbers to j
j.push(i);
}
}
//Copy data array to destination sheet
csh.getRange(csh.getLastRow()+1,1,data.length,data[0].length).
setValues(data);
//Delete matched rows in source sheet ** I Need these to clear data
from B:E for row that it copied and pasted rather then deleted it out.***
for (i=0;i<j.length;i++){
var k = j[i]+1;
sheet.deleteRow(k); // I have tried sheet.Clearcontents, with no sucess
//Alter j to account for deleted rows
if (!(i == j.length-1)) {
j[i+1] = j[i+1]-i-1;
}
}
}
答案 0 :(得分:0)
通过另一个清除所有橙色单元格的脚本,我能够找到另一种清除所需内容的方法。我使用条件格式来使其正常工作。见下文。谢谢。...
>>> class my_class():
... def __init__(self, value):
... self.value = value
... def __mul__(self, n):
... return self.value * n
...
>>> a = my_class(4)
>>> a * 3
12