通过 ID 获取 Google Sheet? [英] Get Google Sheet by ID?

查看:34
本文介绍了通过 ID 获取 Google Sheet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Google Apps 脚本有一个 getSheetId() 方法 对于工作表类,但有没有办法通过引用 ID 在电子表格中选择工作表?

I know that Google Apps Script has a getSheetId() method for the Sheet Class, but is there any way to select a sheet within a spreadsheet by referencing the ID?

我在 电子表格类文档中没有看到类似 getSheetById() 的内容.

推荐答案

你可以这样使用:

function getSheetById(id) {
  return SpreadsheetApp.getActive().getSheets().filter(
    function(s) {return s.getSheetId() === id;}
  )[0];
}

var sheet = getSheetById(123456789);

然后要查找用于活动工作表的工作表 ID,请运行此程序并检查日志或使用调试器.

And then to find the sheet ID to use for the active sheet, run this and check the Logs or use the debugger.

function getActiveSheetId(){
  var id  = SpreadsheetApp.getActiveSheet().getSheetId();
  Logger.log(id.toString());
  return id;
}

这篇关于通过 ID 获取 Google Sheet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆