我是Google脚本的新手,不是编码员。我已经尝试过准确地查找我需要做的事情,但是无法在Google脚本中找到它。
我在一张纸上有公式,需要一个脚本将值从该表复制到另一张纸上的下一个可用行。
数据在表格“订单信息”单元格H40至AC67上。 我需要将值复制到工作表“ Distributed Order List”上的下一个可用行,从A列第2行开始-如果相关的话。
这是我到目前为止可以使用的,但是问题是运行大约需要一分钟:
function enterorder2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange("Order Info!h40:ac40");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h41:ac41");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h42:ac42");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h43:ac43");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h44:ac44");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h45:ac45");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h46:ac46");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h47:ac47");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h48:ac48");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h49:ac49");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h50:ac50");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h51:ac51");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h52:ac52");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h53:ac53");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h54:ac54");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h55:ac55");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h56:ac56");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h57:ac57");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h58:ac58");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h59:ac59");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h60:ac60");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h61:ac61");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h62:ac62");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h63:ac63");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h64:ac64");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h65:ac65");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h66:ac66");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
var source = ss.getRange("Order Info!h67:ac67");
var destSheet = ss.getSheetByName("Distributed Order List");
destSheet.appendRow(source.getValues()[0]);
};
我已经尝试过了,但是我不知道如何将我的值变成“ 1,2,3 4,5,6 7,8,9”:
function enterorder() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var destSheet = ss.getSheetByName("Distributed Order List");
var source = [[1,2,3],[4,5,6],[7,8,9]];
var row = source.length;
var column = source[0].length;
destSheet.getRange(destSheet.getLastRow()+1, 1, row, column).setValues(source);
};
答案 0 :(得分:0)
实际上,您非常接近回答:)。
希望每次运行脚本时,都无法从“订单信息”选项卡的范围H40到AC67复制其他数据,
我正在使用getDataRange(),它从“订单信息”标签中获取所有可用数据,并在您的代码中提供给var源。
function enterorder() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var destSheet = ss.getSheetByName("Distributed Order List");
//var source = [[1,2,3],[4,5,6],[7,8,9]];
var source = ss.getSheetByName("Order Info").getDataRange(); // data feeding
var row = source.length;
var column = source[0].length;
destSheet.getRange(destSheet.getLastRow()+1, 1, row, column).setValues(source);
};
希望这会有所帮助
编辑:
然后使用
var source = ss.getSheetByName(“ Order Info”)。getRange(“ H40:AC67”)。getValues();
代替
var source = ss.getSheetByName(“ Order Info”)。getDataRange();
这将从源工作表中创建所需的范围限制