我需要一些幫助來構建一個應該執行以下操作的簡單腳本:
源電子表格
檢查作業表源上的 Col C 是否等于“完成”
如果是,則將符合條件的 Col A 和 Col B 中的行復制并粘貼到作業表歷史記錄的第一個空行 復制粘貼的時間戳
加上在電子表格 Destination上復制并粘貼 Col A 和 B 中的相同值,選項卡目標上的第一個空行 復制粘貼的時間戳
最后從第一個作業表源中洗掉復制的行,因此沒有空行
如果不是,請將值保留為
總體而言,目標是剪切符合標準的值,并將它們同時粘貼到不同的作業表和不同的電子表格上。
uj5u.com熱心網友回復:
干得好:
function main() {
// get 'Done' rows from sheet 'source' and remove these rows
var data = get_done();
// put the rows on the sheet 'history' (same spreadsheet)
copy_to_history(data);
// pyt the rows on the sheet 'destination' (another spreadsheet)
copy_to_destination(data);
}
function get_done() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('source');
var data = sh.getDataRange().getValues();
var keep = data.filter(x => x[2] != 'Done');
sh.clearContents().getRange(1,1,keep.length,keep[0].length).setValues(keep);
var timestamp = new Date();
var done = data.filter(x => x[2] == 'Done').map(x => [timestamp, x[0], x[1]]);
return done;
}
function copy_to_history(data) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('history');
data.forEach(row => sh.appendRow(row));
}
function copy_to_destination(data) {
var ss = SpreadsheetApp.openById('1niihiUXZii1gNnifn2ZLNf4JnvLs887mJMp53OcIphA');
var sh = ss.getSheetByName('destination');
data.forEach(row => sh.appendRow(row));
}
該腳本的主要缺點:它不保留公式和格式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/480313.html
下一篇:谷歌作業表查找和替換的正則運算式
