【发布时间】:2019-11-12 10:28:14
【问题描述】:
我有一个 copySheet 脚本,可以将数据从一个 google sheet 文件复制到另一个。我用它来查找目标文件。效果很好,但我想进行一些改进。
- 更改 lastCol 以获取工作表中的最后一列,就像行一样。
- 仅从源中复制某些列(A、D、E 列)并按顺序粘贴到目标中(A、B、C 列)
我已经尝试自己使用脚本来完成这两点,但我的知识有限,我无法让它发挥作用。
以下是一些示例文件:
Example - destination (script)
这是脚本:
function copySheet()
{
// Opens the spreadsheet where the data is stored
var sourceTable = SpreadsheetApp.openById("1sp8XFuOAGEfakS_td0xEiX3birz5ckoHNKvzrLPGTOI"); // Source file
var srcSheet = sourceTable.getSheetByName("Sheet1");
// Inserts the data into the target file
var targetTable = SpreadsheetApp.openById("1i77LO4W2paMraipyC_bgx09P7TAuL2cwEVCNxGnbjhs"); // Target file
var tarSheet = targetTable.getSheetByName("Sheet1");
// Gets the last row in the source file
var lastRowSource = srcSheet.getLastRow();
var lastCol = "E";
// Reads the source into an array
var aSrc = srcSheet.getRange("A1:" + lastCol + lastRowSource).getValues();
// Save src array to destination
tarSheet.getRange("A1:" + lastCol + lastRowSource).setValues(aSrc);
}
【问题讨论】:
-
您好,请问您的问题解决了吗?请记住,如果您想将您的问题标记为已解决,您可以accept 任何答案为您的问题提供解决方案。如果情况并非如此,并且您的问题没有得到解决,请考虑解释为什么不是这样,以便该社区可以为您提供帮助。
-
现在已经解决了。我发布了对我有用的答案,谢谢。