简体   繁体   English

Google Appscript更新特定表

[英]Google Appscript update specific sheet

having a bit of a brain dead moment so have come to StackOverflow for a bit of guidance. 有点脑筋急转弯,所以来StackOverflow寻求一些指导。

I currently have a script that I use for recording calendar events from a Group Calendar and pulling them into a Google Spreadsheet so I can work some other magic with them. 目前,我有一个脚本,用于记录来自“组日历”的日历事件并将其拉入Google电子表格,以便我可以使用其他一些魔术。

Currently, it uses: 当前,它使用:

var sheet = SpreadsheetApp.getActiveSheet();

And that works perfectly fine, but as I intend on adding more sheets and I only want this one to update / have the data inserted into, I need to change the .getActiveSheet() part. 这样做非常正常,但是由于我打算添加更多工作表,并且我只希望此工作表更新/将数据插入其中,因此我需要更改.getActiveSheet()部分。 I had tried .getSheetName('name of sheet') , but this returned problems. 我尝试过.getSheetName('name of sheet') ,但这返回了问题。 Can anyone help me out here? 有人可以帮我从这里出去吗? I'm sure it's something simple that I've overlooked. 我敢肯定,这是我忽略了的简单事物。 But I just can't put my finger on it! 但是我只是不能用手指指着它!

Many thanks~ 非常感谢〜

Massive thanks to Sandy for pointing out the blindingly obvious to me! 非常感谢Sandy指出对我来说是盲目的显而易见!

To reference a certain sheet within your spreadsheet, use the following: 要引用电子表格中的特定工作表,请使用以下命令:

var ss = SpreadsheetApp.openById("sheet key")
var sheet = ss.getSheetByName('Sheet Name');

You can also reference sheets by the sheet index number: 您还可以通过图纸索引号引用图纸:

var ss = SpreadsheetApp.getActiveSpreadsheet();
// or .openById('key');

var sheet = ss.Sheets()[i];    
// i = index number

var name = sheet.getName();

This is really helpful in some cases if you have dynamically changing sheet names (eg when you insert, duplicate, rename or delete sheets). 如果您要动态更改工作表名称(例如,在插入,复制,重命名或删除工作表时),这在某些情况下确实很有用。

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

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