/**
* @param {GoogleAppsScript.Events.SheetsOnEdit} e
*/
function onEdit(e) {
if (
e.range.getSheet().getName() === 'Sheet1' &&
e.range.getA1Notation() === 'M2'
)
CopyList();
}
/**
*
*/
function CopyList() {
var sss = SpreadsheetApp.openById('ID-ТАБЛИЦЫ1');
var ss = sss.getSheetByName('Sheet1');
var from = ss;
var fromValues = from.getDataRange().getValues();
var fromData = fromValues;
var tss = SpreadsheetApp.openById('ID-ТАБЛИЦЫ2');
var ts = tss.getSheetByName('Sheet2');
ts.getRange(
ts.getLastRow() + 1,
1,
fromData.length,
fromData[0].length
).setValues(fromData);
}
userActionsCopyToLogs
уже у себя./**
*
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Custom menu')
.addItem('Copy to logs', 'userActionsCopyToLogs')
.addToUi();
}
/**
*
*/
function userActionsCopyToLogs() {
var headers = ['Name', 'Number'];
var from = SpreadsheetApp.getActiveSheet();
if (from.getName() !== 'Sheet1') {
SpreadsheetApp.getActive().toast('Activate a range on "Sheet1"');
return;
}
var fromValues = from.getDataRange().getValues();
var fromHeaders = fromValues[0].map(function(h) {
return headers.indexOf(h);
});
var activeRange = SpreadsheetApp.getActiveRange();
var rowStart = activeRange.getRow();
var rowEnd = activeRange.getLastRow();
var fromData = fromValues
.filter(function(row, i) {
return i >= rowStart - 1 && i <= rowEnd - 1;
})
.map(function(row) {
return row.filter(function(_, j) {
return fromHeaders[j] > -1;
});
});
var to =
SpreadsheetApp.getActive().getSheetByName('Logs') ||
SpreadsheetApp.getActive().insertSheet('Logs');
to.getRange(to.getLastRow() + 1, 1, fromData.length, fromData[0].length)
.setValues(fromData)
.activate();
}
var headers = ['Name', 'Number'];
так, чтобы копировались данные из нужных вам колонок.