Я пытаюсь заставить несколько функций запускаться одновременно при редактировании одной ячейки.
Я пробовал два разных способа, но это не сработало. Когда я запускаю первый вариант без ссылки на ячейку, он работает, но как только я пытаюсь сделать его зависимым от одной ячейки, он перестает работать.
Вариант 1.
function onEdit(e)
{
if (e.range.getA1Notation() === '') {
function AllData(){
importData1();
SpreadsheetApp.flush();
importData2();
SpreadsheetApp.flush();
importData3();
}
}
}
var sourceSpreadsheetID = "XXX";
var sourceWorksheetName = "Sheet1";
var targetSpreadsheetID = "yyy";
var targetWorksheetName = "Sheet 2";
function importData1() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
var thisData = thisSpreadsheet.getRangeByName("data1");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(9, 2, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
var sourceSpreadsheetID = "XXX";
var sourceWorksheetName = "Sheet1";
var targetSpreadsheetID = "yyy";
var targetWorksheetName = "Sheet 2";
function importData2() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
var thisData = thisSpreadsheet.getRangeByName("data2");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(9, 7, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
var sourceSpreadsheetID = "XXX";
var sourceWorksheetName = "Sheet1";
var targetSpreadsheetID = "yyy";
var targetWorksheetName = "Sheet 2";
function importData3() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
var thisData = thisSpreadsheet.getRangeByName("data3");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(9, 11, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
Вариант 2.
function createOnEditTrigger() {
var ss = SpreadsheetApp.openById(targetSpreadsheetID);
ScriptApp.newTrigger("importData")
.forSpreadsheet(ss)
.onEdit()
.create();
}
var sourceSpreadsheetID = "1qu_AheZoX6Z4H1GF2yBwvlFxLlCkQhmuYfg-fP8z2kc";
var sourceWorksheetName = "tankers-tool-database";
var targetSpreadsheetID = "1ozefsBT-LBmWXPI4QqDG4BSAzfmY_Yqp2q_sXTevhpk";
var targetWorksheetName = "tankers-search-db";
function importData(e) {
if (e.range.getA1Notation() === "A1") {
function AllData(){
importData1();
SpreadsheetApp.flush();
importData2();
SpreadsheetApp.flush();
importData3();
}
}
}
function importData1() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
//Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.
var thisData = thisSpreadsheet.getRangeByName("data1");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(9, 2, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
function importData2() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
//Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.
var thisData = thisSpreadsheet.getRangeByName("data2");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(9, 7, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}
function importData3() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
//Uncomment line 11 below and comment out line 9 if you want to sync a named range. Replace "teamBugs" with your named range.
var thisData = thisSpreadsheet.getRangeByName("data3");
var toSpreadsheet = SpreadsheetApp.openById(targetSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(targetWorksheetName);
var toRange = toWorksheet.getRange(9, 11, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(thisData.getValues());
}