简体   繁体   English

如何使用 Google Apps 脚本引用外部电子表格

[英]How to reference an external spreadsheet with Google Apps Scripts

Update: It worked for 5 minutes then stopped working again.更新:它工作了 5 分钟,然后又停止工作了。 Not exactly sure why it's only working part of the time?不确定为什么它只在部分时间工作?

This sounds like it's supposed to be simple but I'm only finding information on "getActive" and my function works if I'm using all internal sheets but I tried using openById and nothing happened and openByUrl returns an error.这听起来应该很简单,但我只找到有关“getActive”的信息,如果我使用所有内部工作表,我的 function 可以工作,但我尝试使用openById但没有任何反应, openByUrl返回错误。 The following is a simplified example of what I'm trying to do:以下是我正在尝试做的一个简化示例:

  var store_data_sheet = SpreadsheetApp.openByID('ID here..').getSheetByName('Data'); 
  store_data_sheet.getRange('A1').setValue('testing')
  store_data_sheet.insertRows(1);

I'm sure I'm just using the wrong keywords or maybe this isn't even allowed but multiple users will be using their own copy of a specific sheet that runs this function and I'd just like to take certain cell's data and copy it to one external sheet (which is why it also inserts a row so it can push down entries) Maybe I'm using the wrong "ID"?我确定我只是使用了错误的关键字,或者甚至不允许这样做,但多个用户将使用他们自己的运行此 function 的特定工作表的副本,我只想获取某些单元格的数据并复制它到一个外部工作表(这就是为什么它也插入一行以便它可以下推条目)也许我使用了错误的“ID”? I assumed the number inside the URL was the ID.我假设 URL 中的数字是 ID。 If it's something more specific, please let me know.如果它更具体,请告诉我。

Like I said, this works flawlessly if I'm referencing an internal sheet.就像我说的,如果我引用的是内部工作表,这将完美无缺。 I'd like to be able to do the same exact thing with an external spreadsheet if possible.如果可能的话,我希望能够用外部电子表格做同样的事情。 Thank you!谢谢!

I found the issue.我发现了问题。 This function also renames the sheet file so if there is anything in the cell that is used to rename the file, it won't run the storing functions.此 function 还重命名了工作表文件,因此如果单元格中有任何用于重命名文件的内容,它将不会运行存储功能。 I either need to run these before the renaming or take out the renaming aspect.我要么需要在重命名之前运行这些,要么删除重命名方面。 ---moving these before the renaming part fixed the problem. ---在重命名部分之前移动这些解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM