我放在一起这个测试:谷歌工作表复制行,以不同的电子表格
的功能:在列表选项卡,当您更改列B的名称,该行的一部分被复制到匹配表。
我需要的是将它们复制到单独的电子表格(每个雇主一个)。那可能吗?
我的代码:
// http://victorwyee.com/gapps/move-row-on-cell-value-google-spreadsheets/
/**
* Moves row of data to another spreadsheet based on criteria in column 6.
* Each spreadsheet can be a "source" spreadsheet, or the "target" spreadsheet.
* Assumes there as many spreadsheets as there are criteria values, e.g.
* if the criteria are "R", "P", and "D", then there are three spreadsheets
* named "R", "P" and "D".
* Assumes that each spreadsheet has the same structure.
*/
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
var r = SpreadsheetApp.getActiveRange();
// Get the row and column of the active cell.
var rowIndex = r.getRowIndex();
var colIndex = r.getColumnIndex();
// Get the number of columns in the active sheet.
var colNumber = s.getLastColumn();
// Move row based on criteria in column 6, and if row is not the header.
if (colIndex == 2 && rowIndex != 1) {
// Get value from column 6, in the active row.
var status = s.getRange(rowIndex, colIndex).getValue();
// Do nothing if criteria value is not actually changed to something else.
if (s.getName() != status) {
// The target sheet is the one with the same name as the criteria value.
var targetSheet = ss.getSheetByName(status);
var target = targetSheet.getRange(targetSheet.getLastRow() +1, 1);
// Set the range and copy
// s.getRange(rowIndex, 10, 1, colNumber).copyTo(target);
targetSheet.insertRowsAfter(targetSheet.getLastRow(), 1);
s.getRange(rowIndex, 1, 1, 16).copyTo(target);
// s.deleteRow(rowIndex);
}
}
}
已经取得了一些变化,从而不被更新的意见。