问题描述
是否可以通过 Google Apps 脚本打开 Google 电子表格?
我正在尝试创建一种链接到电子表格中某个单元格的方法,但我无法通过脚本(部署为网络应用程序)打开工作表.
我想打开电子表格,然后设置活动工作表和范围(当电子表格打开时,我知道如何做后者).
Is it possible to open a Google Spreadsheet via Google Apps script?
I'm trying to create a way to link to a certain cell in a spreadsheet, but I can't manage to open a sheet from a script (deployed as a web app).
I want to open the spreadsheet and then set the active sheet and range (I know how to do the latter, when the spreadsheet is opened).
提前致谢!
编辑
这是我当前的代码:
EDIT
Here's my current code:
function doGet(e){
var ss = SpreadsheetApp.openById("[id]");
SpreadsheetApp.setActiveSpreadsheet(ss);
var sheet = ss.getSheetByName("Kunder");
var row = Number(e.parameter.row);
var col = Number(e.parameter.col);
var range = sheet.getRange(row, col);
//OPEN THE SPREADSHEET HERE
SpreadsheetApp.setActiveSheet(sheet);
SpreadsheetApp.setActiveRange(range);
}
推荐答案
您需要为电子表格使用正确的 ID.找到它的一种方法是:
You need to use the correct ID for the spreadsheet. One way to find it is:
- 在 Google Drive 中打开包含文件夹
- 右键点击电子表格
- 选择获取链接
- 复制显示的网址
URL 将采用以下格式:https://drive.google.com/open?id=xoxoxoxoxoxoxoxoxoxoxoxo
The URL will be in the form:https://drive.google.com/open?id=xoxoxoxoxoxoxoxoxoxoxoxo
使用 id 参数值作为 openById 的参数,例如:
Use the id parameter value as the argument to openById, e.g.:
var ss = SpreadsheetApp.openById("xoxoxoxoxoxoxoxoxoxoxoxo");
var ss = SpreadsheetApp.openById("xoxoxoxoxoxoxoxoxoxoxoxo");
这篇关于通过 Google Apps 脚本打开 Google 电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!