如何通过Google Apps脚本访问不同Google电子表格上的数据? [英] How to access data on different Google Spreadsheet through Google Apps Script?
问题描述
我正在Google网站上撰写Google Apps脚本,并试图使用Google Spreadsheet中两个不同标签上提供的数据。从我认为我从文档中理解的内容中,我可以通过使用 openById()来使用Sites脚本的
SpreadsheetApp
类中的所有可用方法。 / code>方法。
I'm writing a Google Apps Script on my Google Site and am trying to use data that is provides on 2 different tabs in a Google Spreadsheet. From what I thought I understood from the documentation I could use all available methods in the SpreadsheetApp
class on a Sites script by just using the openById()
method.
无论如何这里是我试图做的事情$ / $>
Anyway here is what I tried to do
function doGet(e) {
var doc = SpreadsheetApp.openById(SPREADSHEET_ID_GOES_HERE).getActiveSheet();
SpreadsheetApp.setActiveSheet(doc.getSheetId()[1]);
//....
}
我得到错误
I get the error
无法找到方法setActiveSheet(。(line 4)
Cannot find method setActiveSheet(. (line 4)
我正在将我的作品从此链接中删除:在Google Spreadsheets中存储数据以及在建筑用户界面下列出的Ui服务部分。
I'm pulling my work off this link: Storing Data in Google Spreadsheets and also the Ui Service section listed under Building User Interfaces.
任何人看到我在这两行中做错了什么?
Anybody seeing what I'm doing wrong in these two lines?
推荐答案
setActiveSheet只能用于用户界面显示的电子表格,即用户在浏览器中打开的电子表格中的工作表。
setActiveSheet should be used only with the spreadsheet displayed by the UI, a sheet in a spreadsheet you have opened in your browser.
使用SpreadsheetApp.openById,您将打开一个电子表格来访问其数据,但它不会在您的浏览器中打开,它没有UI。
With SpreadsheetApp.openById you are opening a spreadsheet to access its data, but it doesn't open in your browser. It hasn't an UI.
我在 https://developers.google.com/apps-script/class_spreadsheetapp?hl=es-ES#openById :
// The code below opens a spreadsheet using it's ID and gets the name for it.
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
var ss = SpreadsheetApp.openById("abc1234567");
一些示例假设您的脚本正在运行到您的电子表格中。这不是你的情况,因为你正在运行脚本作为服务,它应该有它自己的用户界面。
Some examples assume your script is running into your spreadsheet. It's not your case, because you are running a script as a service, which should have its own User Interface.
这篇关于如何通过Google Apps脚本访问不同Google电子表格上的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!