通过 url 向文档添加编辑器
Adding editors to a document by url
正如我在这个回答中看到的:
我想add/removeeditors/viewers到很多电子表格,但是我有URL,我没有定位到每个文档(sheets)。账号运行这个脚本是每个文件的owner/creator
function addEditors() {
var emails = [
'john@example.com',
'steve@example.com',
'bill@example.com'
];
DocumentApp.getActiveDocument().addEditors(emails);
}
我找不到类似 DocumentApp.getDocumtByURL('URL').addEditors(emails);
的内容
我在电子表格中有所有 URL,我想我可以 parse/get ID,但是我如何 add/remove editors/viewers?
我相信你的目标如下。
- 您有几个 URL 的 Google 电子表格,您想使用 Google Apps 脚本添加编辑者和查看者。
- 而且,你想删除它们。
- Spreadsheet 的 URL 就像
https://docs.google.com/spreadsheets/d/###/edit
.
修改点:
- 在您的脚本中,似乎使用了 Google 文件。所以在这种情况下,需要使用电子表格服务。
- 当电子表格有多个 URL 时,您可以在循环中使用每个 URL。
修改后的脚本 1:
在此脚本中,emails
被添加为 URL 电子表格的编辑器。
function addEditors() {
var urls = [
"https://docs.google.com/spreadsheets/d/###/edit",
"https://docs.google.com/spreadsheets/d/###/edit",
,
,
,
];
var emails = ["###","###",,,];
urls.forEach(url => {
SpreadsheetApp.openByUrl(url).addEditors(emails);
});
}
- 当您要将邮箱添加为查看者时,请将
addEditors(emails)
修改为addViewers(emails)
。
修改后的脚本 2:
在此脚本中,删除了 emails
的编辑器以用于 URL 的电子表格。
function removeEditors() {
var urls = [
"https://docs.google.com/spreadsheets/d/###/edit",
"https://docs.google.com/spreadsheets/d/###/edit",
,
,
,
];
var emails = ["###","###",,,];
urls.forEach(url => {
emails.forEach(email => SpreadsheetApp.openByUrl(url).removeEditor(email));
});
}
- 如果要删除带邮件的查看者,请将
removeEditor(email)
修改为removeViewer(email)
。
参考文献:
正如我在这个回答中看到的:
我想add/removeeditors/viewers到很多电子表格,但是我有URL,我没有定位到每个文档(sheets)。账号运行这个脚本是每个文件的owner/creator
function addEditors() {
var emails = [
'john@example.com',
'steve@example.com',
'bill@example.com'
];
DocumentApp.getActiveDocument().addEditors(emails);
}
我找不到类似 DocumentApp.getDocumtByURL('URL').addEditors(emails);
我在电子表格中有所有 URL,我想我可以 parse/get ID,但是我如何 add/remove editors/viewers?
我相信你的目标如下。
- 您有几个 URL 的 Google 电子表格,您想使用 Google Apps 脚本添加编辑者和查看者。
- 而且,你想删除它们。
- Spreadsheet 的 URL 就像
https://docs.google.com/spreadsheets/d/###/edit
.
修改点:
- 在您的脚本中,似乎使用了 Google 文件。所以在这种情况下,需要使用电子表格服务。
- 当电子表格有多个 URL 时,您可以在循环中使用每个 URL。
修改后的脚本 1:
在此脚本中,emails
被添加为 URL 电子表格的编辑器。
function addEditors() {
var urls = [
"https://docs.google.com/spreadsheets/d/###/edit",
"https://docs.google.com/spreadsheets/d/###/edit",
,
,
,
];
var emails = ["###","###",,,];
urls.forEach(url => {
SpreadsheetApp.openByUrl(url).addEditors(emails);
});
}
- 当您要将邮箱添加为查看者时,请将
addEditors(emails)
修改为addViewers(emails)
。
修改后的脚本 2:
在此脚本中,删除了 emails
的编辑器以用于 URL 的电子表格。
function removeEditors() {
var urls = [
"https://docs.google.com/spreadsheets/d/###/edit",
"https://docs.google.com/spreadsheets/d/###/edit",
,
,
,
];
var emails = ["###","###",,,];
urls.forEach(url => {
emails.forEach(email => SpreadsheetApp.openByUrl(url).removeEditor(email));
});
}
- 如果要删除带邮件的查看者,请将
removeEditor(email)
修改为removeViewer(email)
。