将行从一个工作表复制到其他工作表会意外停止

时间:2017-10-01 21:44:59

标签: javascript google-apps-script google-sheets google-apps

我有一个很大的主表,我想从那里填写10个较小的表,以获得类似报告(工作表打印)。我在不同条件下填写工作表并为此编写脚本(认为这是唯一的方法)。如果我只为一个表运行脚本它可以工作,但如果我运行它来填充所有表,它会在某处(每次在不同的地方)意外停止,现在我只有4行。当主表用于工作时,它可能有300行。 这是电子表格https://docs.google.com/spreadsheets/d/1T6ujnZFdXYoC9n71RH8fm0EXKoyrUAYJGI-v5dwoDso/edit?usp=sharing

的链接

这是剧本

function doTables() {
var sheetNameToMoveFrom = "Главен лист";
var ss = SpreadsheetApp.getActiveSpreadsheet();//we get the speadsheet we are using
var sheetToMoveFrom = ss.getSheetByName(sheetNameToMoveFrom);// we store the object of the sheet to move from
var theLastRow = sheetToMoveFrom.getLastRow(); //store the num of rows with content
var valueToWatchYES = "да";
var valueToWatchNO = "не";

var sheetNameToMoveTheRowTo1 = "1.ряз за ламинат";
var sheetToMoveTo1 = ss.getSheetByName(sheetNameToMoveTheRowTo1);// we store the object of the sheet to move to
var columnNumberToWatch1 = 39; // column A = 1, B = 2, etc.
var theLastRow1 = sheetToMoveTo1.getLastRow();
sheetToMoveTo1.deleteRows(3,theLastRow1);// delete all rows from the table that we will copy into, so if there is a change on some row to apply 
var theFreeRow1 = 3;

var sheetNameToMoveTheRowTo2 = "2.ряз за кант";
var sheetToMoveTo2 = ss.getSheetByName(sheetNameToMoveTheRowTo2);// we store the object of the sheet to move to
var columnNumberToWatch21 = 15; // column A = 1, B = 2, etc.
var columnNumberToWatch22 = 18; // column A = 1, B = 2, etc.
var columnNumberToWatch23 = 22; // column A = 1, B = 2, etc.
var theLastRow2 = sheetToMoveTo2.getLastRow();
sheetToMoveTo2.deleteRows(3,theLastRow2);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow2 = 3;

var sheetNameToMoveTheRowTo3 = "3.закалено за ламиниране";
var sheetToMoveTo3 = ss.getSheetByName(sheetNameToMoveTheRowTo3);// we store the object of the sheet to move to
var columnNumberToWatch3 = 40; // column A = 1, B = 2, etc.
var theLastRow3 = sheetToMoveTo3.getLastRow();
sheetToMoveTo3.deleteRows(3,theLastRow3);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow3 = 3;

var sheetNameToMoveTheRowTo4 = "4.готов продукт за опаковане";
var sheetToMoveTo4 = ss.getSheetByName(sheetNameToMoveTheRowTo4);// we store the object of the sheet to move to
var columnNumberToWatch41 = 41; // column A = 1, B = 2, etc.
var columnNumberToWatch42 = 42; // column A = 1, B = 2, etc.
var theLastRow4 = sheetToMoveTo4.getLastRow();
sheetToMoveTo4.deleteRows(3,theLastRow4);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow4 = 3;

var sheetNameToMoveTheRowTo5 = "5.опис за ишлемета";
var sheetToMoveTo5 = ss.getSheetByName(sheetNameToMoveTheRowTo5);// we store the object of the sheet to move to
var columnNumberToWatch5 = 32; // column A = 1, B = 2, etc.
var theLastRow5 = sheetToMoveTo5.getLastRow();
sheetToMoveTo5.deleteRows(3,theLastRow5);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow5 = 3;

var sheetNameToMoveTheRowTo6 = "6.опис стъкла за кантиране";
var sheetToMoveTo6 = ss.getSheetByName(sheetNameToMoveTheRowTo6);// we store the object of the sheet to move to
var columnNumberToWatch6 = 15; // column A = 1, B = 2, etc.
var theLastRow6 = sheetToMoveTo6.getLastRow();
sheetToMoveTo6.deleteRows(3,theLastRow6);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow6 = 3;

var sheetNameToMoveTheRowTo7 = "7.опис стъкла за пробиване";
var sheetToMoveTo7 = ss.getSheetByName(sheetNameToMoveTheRowTo7);// we store the object of the sheet to move to
var columnNumberToWatch7 = 18; // column A = 1, B = 2, etc.
var theLastRow7 = sheetToMoveTo7.getLastRow();
sheetToMoveTo7.deleteRows(3,theLastRow7);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow7 = 3;

var sheetNameToMoveTheRowTo8 = "8.опис стъкла за цифрова обработка";
var sheetToMoveTo8 = ss.getSheetByName(sheetNameToMoveTheRowTo8);// we store the object of the sheet to move to
var columnNumberToWatch8 = 22; // column A = 1, B = 2, etc.
var theLastRow8 = sheetToMoveTo8.getLastRow();
sheetToMoveTo8.deleteRows(3,theLastRow8);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow8 = 3;

var sheetNameToMoveTheRowTo9 = "9.опис стъкла за облепване";
var sheetToMoveTo9 = ss.getSheetByName(sheetNameToMoveTheRowTo9);// we store the object of the sheet to move to
var columnNumberToWatch91 = 27; // column A = 1, B = 2, etc.
var columnNumberToWatch92 = 43; // column A = 1, B = 2, etc.
var theLastRow9 = sheetToMoveTo9.getLastRow();
sheetToMoveTo9.deleteRows(3,theLastRow9);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow9 = 3;

var sheetNameToMoveTheRowTo10 = "10.опис стъкла за ламиниране";
var sheetToMoveTo10 = ss.getSheetByName(sheetNameToMoveTheRowTo10);// we store the object of the sheet to move to
var columnNumberToWatch101 = 43; // column A = 1, B = 2, etc.
var columnNumberToWatch102 = 5; // column A = 1, B = 2, etc.
var theLastRow10 = sheetToMoveTo10.getLastRow();
sheetToMoveTo10.deleteRows(3,theLastRow10);// delete all rows from the table that we will copy into, so if there is a change on some row to apply
var theFreeRow10 = 3;

var rangeToCopy;
var rangeToRecieveCopy;

//loop through all the rows that the sheet we will copy from have and look for what matter for you
for(var i=1; i<=theLastRow; i++)
{
  //table 1
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch1).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("H"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("I"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("J"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("M"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("N"+i);
      rangeToRecieveCopy = sheetToMoveTo1.getRange(theFreeRow1,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow1++;
  }
  //table 2
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch21).getValue() == valueToWatchYES || sheetToMoveFrom.getRange(i,columnNumberToWatch22).getValue() == valueToWatchYES || sheetToMoveFrom.getRange(i,columnNumberToWatch23).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("F"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("G"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("M"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("N"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("P"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("T"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,12);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("Y"+i);
      rangeToRecieveCopy = sheetToMoveTo2.getRange(theFreeRow2,13);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow2++;
  }
  //table 3
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch3).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("H"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("I"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("J"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("M"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("N"+i);
      rangeToRecieveCopy = sheetToMoveTo3.getRange(theFreeRow3,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow3++;
  }
  //table 4
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch41).getValue() == valueToWatchYES || sheetToMoveFrom.getRange(i,columnNumberToWatch42).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("H"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("I"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("J"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("M"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("N"+i);
      rangeToRecieveCopy = sheetToMoveTo4.getRange(theFreeRow4,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow4++;
  }
  //table 5
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch5).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("F"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("H"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("J"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("M"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("AG"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("AH"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,12);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("AI"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,13);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("AJ"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,14);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("AK"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,15);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("AL"+i);
      rangeToRecieveCopy = sheetToMoveTo5.getRange(theFreeRow5,16);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow5++;
  }
  //table 6
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch6).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("F"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("G"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("M"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("P"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("Q"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("R"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo6.getRange(theFreeRow6,12);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow6++;
  }
  //table 7
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch7).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("S"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("T"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("U"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("I"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("J"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo7.getRange(theFreeRow7,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow7++;
  }
  //table 8
  if(sheetToMoveFrom.getRange(i,columnNumberToWatch8).getValue() == valueToWatchYES)
  {
      rangeToCopy = sheetToMoveFrom.getRange("A"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,1);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("B"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,2);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("C"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,3);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("D"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,4);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("E"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,5);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("I"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,6);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("J"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,7);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("K"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,8);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("W"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,9);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("X"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,10);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("Y"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,11);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      rangeToCopy = sheetToMoveFrom.getRange("Z"+i);
      rangeToRecieveCopy = sheetToMoveTo8.getRange(theFreeRow8,12);
      rangeToCopy.copyTo(rangeToRecieveCopy);
      theFreeRow8++;
  }
  }
  }
  function onEdit(e) {
      if (e.source.getActiveSheet().getName() !== "други" || e.range.rowStart != 1 || e.range.columnStart != 9) return;
      if(e.source.getSheetByName("други").getRange(1,9).getValue() == "да"){
        doTables();
        e.source.getSheetByName("други").getRange(1,9).setValue("готово");
      }
  }

1 个答案:

答案 0 :(得分:0)

如果你的脚本超时(即超过6分钟的脚本限制),那么你可以试试这里。我只修改了前三个部分,但看起来有些重复。我猜你如果你要使用getValues和setValues并对你的工作表进行参数化(可能在一个数组中)你可能会将这整个函数降低到少于50行的代码,这些代码的运行速度比现在快了一个数量级。 。如果我在我面前掌握了所有数据并且我理解了语言,那么我就可以在不到3个小时的时间内了解正在发生的事情。其他一些程序员可能会在不到这一点的情况下完成它。

template <auto Deleter>
struct FuncDeleter {
    template <class P>
    void operator()(P* p) const { Deleter(p); }
};

std::unique_ptr<char, FuncDeleter<std::free>> cs(get_c_string());