将小组成员列表写到工作表Google脚本

时间:2019-02-22 17:44:30

标签: google-apps-script google-sheets

我想将Google域中某个组的所有成员的列表写到Google工作表中。我在Google论坛上找到了此脚本,但我不希望结果进入日志,我希望它们进入活动的表单。谁能解释如何做到这一点?

https://developers.google.com/apps-script/reference/groups/group#getUsers()

function listGroupMembers() {
  var GROUP_EMAIL = "example@googlegroups.com";
  var group = GroupsApp.getGroupByEmail(GROUP_EMAIL);
  var users = group.getUsers();
  var str = "Group " + GROUP_EMAIL + " has " + users.length +
  " members: ";
  for (var i = 0; i < users.length; i++) {
    var user = users[i];
    str = str + user.getEmail() + ", ";
  }
  Logger.log(str);
}

1 个答案:

答案 0 :(得分:0)

谢谢。你让我走上了正确的道路。对于访问此页面并寻找相同答案的任何人,这就是我的想法。

function listGroupMembers() {
  var GROUP_EMAIL = "groups@google.com";
  var group = GroupsApp.getGroupByEmail(GROUP_EMAIL);
  var users = group.getUsers();
  var str ="";
  for (var i = 0; i < users.length; i++) {
    var user = users[i];
    str = str + user.getEmail() + ", " + "\n";
  }
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[1];
var range = sheet.getRange(1,1,1);
range.setValue(str);
var csvData = Utilities.parseCsv(str);
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);


}