我有一些谷歌脚本,我正在使用它能够以特定顺序将名为"Sheet2"的工作表的所有行复制到名为"Invitations en cours"的目标工作表中。
在工作表2的第一列是一个面板代码,我正在检索它,以便能够知道我应该将行复制到目标工作表中的确切位置,该工作表还包含一次每个面板代码。
基本上,我遍历Sheet2中的所有行,并将所有非空行复制到右侧面板代码下的"Invitations en cours"中,该代码位于第一列中。
我有两个问题:1) 我如何确保在邀请函中创建一个新的行,而不覆盖已经存在的内容?我找不到合适的函数。2) 为什么它说缺少)论点行54?我在这里找不到我做错了什么。
//We get the range we want to eventually copy
var rowRange = sheet.getRange("A"+i:"Z"+i);
非常感谢你的帮助,请耐心等待,这是我第一次编码!
function onOpen() {
//Adding menu
var ui = SpreadsheetApp.getUi();
ui.createMenu('Fonctions spéciales')
.addItem('Copier range', 'CopyRange')
.addToUi();
}
function CopyRange() {
SpreadsheetApp.getUi()
var source = SpreadsheetApp.getActiveSpreadsheet();
var lastRow = source.getLastRow();
var sheet = source.getSheetByName("Sheet2");
var i = 2;
var r = i;
var cell = source.getActiveCell();
var sheetDestination = source.getSheetByName("Invitations en cours");
var range = sheetDestination.getRange("A"+r);
var cellFind = range.getCell(r, "A");
var value = cellFind.getValue();
//finding the right panel codes in the first column of the destination sheet
for (r; r < lastRow; r++) {
switch(value) {
case "co":
var confCo = cellFind;
break;
case "ca":
var confCa = cellFind;
break;
case "1":
var panelUn = cellFind;
break;
case "2":
var panelDeux = cellFind;
break;
case "3":
var panelTrois = cellFind;
break;
case "4":
var panelQuatre = cellFind;
break;
case "5":
var panelCinq = cellFind;
break;
case "6":
var panelSix = cellFind;
break;
}
}
//Copying each row to the destination sheet under the right panel code
while (i <= lastRow) {
i++
//We get the range we want to eventually copy
var rowRange = sheet.getRange("A"+i:"Z"+i);
//We check for blanks
if (sheet.getRange("A"+i).getValue()!=="") {
//We create a row under the panel codes we looked for earlier
switch("A"+i.getValue()) {
case "co":
rowRange.copyValuesToRange(sheetDestination, 2, 26, confCo.getColumn(), confCo.getColumn());
break;
case "ca":
rowRange.copyValuesToRange(sheetDestination, 2, 26, confCa.getColumn(), confCa.getColumn());
break;
case "AM1":
rowRange.copyValuesToRange(sheetDestination, 2, 26, panelUn.getColumn(), panelUn.getColumn());
break;
case "AM2":
rowRange.copyValuesToRange(sheetDestination, 2, 26, panelDeux.getColumn(), panelDeux.getColumn());
break;
case "AM3":
rowRange.copyValuesToRange(sheetDestination, 2, 26, panelTrois.getColumn(), panelTrois.getColumn());
break;
case "PM1":
rowRange.copyValuesToRange(sheetDestination, 2, 26, panelQuatre.getColumn(), panelQuatre.getColumn());
break;
case "PM2":
rowRange.copyValuesToRange(sheetDestination, 2, 26, panelCinq.getColumn(), panelCinq.getColumn());
break;
case "PM3":
rowRange.copyValuesToRange(sheetDestination, 2, 26, panelSix.getColumn(), panelSix.getColumn());
break;
default:`enter code here`
text = "Je ne trouve pas un des codes panels suivants : co, ca, AM1, AM2, AM3, PM1, PM2, PM3. Avez-vous copié les codes panels?";
}
}
}
}
字符串连接似乎有问题。
sheet.getRange("A"+i:"Z"+i);
应该是
sheet.getRange("A"+i + ":Z"+i);