gpt4 book ai didi

javascript - 参数列表 Google 脚本后缺少 )

转载 作者:行者123 更新时间:2023-12-03 11:36:19 28 4
gpt4 key购买 nike

我有一些 Google 脚本,用于将名为“Sheet2”的工作表中的所有行按特定顺序复制到名为“Invitations en cours”的目标工作表中。

在工作表 2 的第一列中是一个面板代码,我正在检索该代码,以便能够知道我应该将该行复制到目标工作表中的确切位置,该目标工作表也包含一次每个面板代码。

基本上,我会遍历 Sheet2 中的所有行,并将所有非空行复制到右侧面板代码下的“Invitations en cours”,该代码位于其第一列中。

我有两个问题:1) 如何确保在类(class)邀请中创建新行而不覆盖已有内容?我无法找到合适的功能。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);

关于javascript - 参数列表 Google 脚本后缺少 ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26494256/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com