将工作簿 A 中的工作表 1 复制到工作簿 B 的工作表 1

发布于 2025-01-16 19:06:26 字数 725 浏览 2 评论 0原文

我正在尝试将工作表从我所说的“主”工作簿复制到我的员工可以访问的工作簿,但我似乎无法复制它。

一旦我有了脚本,我就会将其设置为每天复制。这样我就可以编辑主文件,它基本上每天都会为我的员工“自动更新”。

function copyDoc() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('General');

var targetSheet = SpreadsheetApp.openById('13ERWTQoXeGb0cIfgfr2ZTsImnwmtaVB5c-Zm9ZZ5o6g').getSheetByName('General');

sourceSheet.copyTo(targetSheet);
}

它只是告诉我有一个错误:

错误
异常:参数 (number,number,number,null) 与 SpreadsheetApp.Sheet.getRange 的方法签名不匹配。 copyDoc @测试 Copy.gs:11

我完全不知道我在做什么或应该做什么。本质上,我每天都需要将工作簿 A 中的工作表 1 到工作表 7 复制到工作簿 B 的工作表 1 到工作表 7 中。但这些工作表都已经在每个工作簿中并带有标题。

屏幕截图

I'm trying to copy sheets from what I'm calling a "Master" workbook to a workbook that my staff has access to but I can't seem to get it to copy.

Once I have the script, I'm going to set it up to copy every day. That way I can edit the Master and it will essentially "auto update" for my staff every day.

function copyDoc() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('General');

var targetSheet = SpreadsheetApp.openById('13ERWTQoXeGb0cIfgfr2ZTsImnwmtaVB5c-Zm9ZZ5o6g').getSheetByName('General');

sourceSheet.copyTo(targetSheet);
}

It just tells me there's an error:

Error
Exception: The parameters (number,number,number,null) don't match the method signature for SpreadsheetApp.Sheet.getRange.
copyDoc @ Test Copy.gs:11

I have absolutely no idea what I'm doing or what I should be doing. Essentially I need to copy Sheet 1 through 7 from Workbook A into Sheet 1 through 7 of Workbook B every single day. But the sheets are all already in each Workbook and titled.

Screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒路情人 2025-01-23 19:06:26

屏幕截图显示您的项目有 4 个文件。

具有您尝试执行的函数的文件位于文件 Copy Daily.gs 中。该文件只有 7 行。该错误不属于该文件(如下所述)。

  1. Test Copy.gs 是包含导致错误的语句的文件名。
  2. 11Test Copy.gs 文件的行号。
  3. getRange 是有问题的方法,

很可能发生错误,因为文件 Test Copy.gs 中引用的行位于全局中范围。全局范围内的语句,无论它们在哪个文件上,都会在执行调用的函数之前执行。

可能的修复方法:

  1. 打开 Test Copy.gs 文件
  2. 在第 11 行开头添加 //

另一种选择是删除 Test Copy.gs  文件。如果您有关于该文件的有价值的信息,请在删除它之前进行适当的备份。

相关

The screenshot shows that your project has 4 files.

The file having the function that you are trying to execute is in file Copy Daily.gs. This file has only 7 lines. The error doesn't belong to that file (as explained below).

  1. Test Copy.gs is the file name having the statement causing the error.
  2. 11 is the line number of the Test Copy.gs file.
  3. getRange is the method having the problem

It's very likely that the error is occurring because the referred line from file Test Copy.gs is in the global scope. Statements in the global scope, no matter on which file they are, are executed before executing the function called.

Possible fix:

  1. Open the Test Copy.gs file
  2. Add // at the beginning of line 11

Another option is to delete the Test Copy.gs file. If you have valuable information on that file, before deleting it, make an appropriate backup.

Related

°如果伤别离去 2025-01-23 19:06:26

我在 Reddit 上询问,结果成功了!

function copyDoc() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('General');
var target = SpreadsheetApp.openById('13ERWTQoXeGb0cIfgfr2ZTsImnwmtaVB5c-Zm9ZZ5o6g');
sourceSheet.copyTo(target);
target.deleteSheet(target.getSheetByName("General"));
var targetSheet = target.getSheetByName("Copy of General")
target.setActiveSheet(targetSheet)
target.moveActiveSheet(1);
targetSheet.setName("General");
}

然后,我只需复制并粘贴它并更改工作表的名称,因为它适用于我在一份文档中拥有的所有工作表。

I asked on Reddit and this ended up working!

function copyDoc() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('General');
var target = SpreadsheetApp.openById('13ERWTQoXeGb0cIfgfr2ZTsImnwmtaVB5c-Zm9ZZ5o6g');
sourceSheet.copyTo(target);
target.deleteSheet(target.getSheetByName("General"));
var targetSheet = target.getSheetByName("Copy of General")
target.setActiveSheet(targetSheet)
target.moveActiveSheet(1);
targetSheet.setName("General");
}

I then just copied and pasted it and changed the name of the sheets for it work across all of the sheets I have in one document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文