我正在使用内置的组服务来提取用户名列表......
function getUsersInGroup(group) {
var usersInGroup = GroupsApp.getGroupByEmail(group).getUsers();
return usersInGroup;
}
...它返回一个数组,像这样...
[ [email protected] /cdn-cgi/l/email-protection, [email protected] /cdn-cgi/l/email-protection, [email protected] /cdn-cgi/l/email-protection ]
What I would like is for those emails to show up in a spreadsheet column like this...
似乎 Apps 脚本的 .setValues() 需要一个 2D 数组,即使数据是“平坦”的,所以我从测试中得到的印象是我的数据必须采用这样的格式......
var data = [[[email protected] /cdn-cgi/l/email-protection],[[email protected] /cdn-cgi/l/email-protection],[[email protected] /cdn-cgi/l/email-protection]]
如果我希望它显示为数据行而不是列中的一项。
如果我是正确的,我想我正在寻找我的问题的两个(也许三个)可能答案中最好的一个。
我认为可能的解决方案
变换数组,使数组中的每一项成为一项数组
可能有一个 for 循环
找出一个更好的内置函数
数组并将其变成一行数据
我还可以做一些我在这里根本没有考虑过的事情
如果您不想循环,也可以使用 Sheets API。
Use 高级谷歌服务 https://developers.google.com/sheets/api/guides/values#writing_to_a_single_range并将majorDimension切换为列:
var data = [ '[email protected] /cdn-cgi/l/email-protection', '[email protected] /cdn-cgi/l/email-protection', '[email protected] /cdn-cgi/l/email-protection' ];
var request = {
range: 'Sheet1!A1',
majorDimension: 'COLUMNS',
values: [data], //still 2D
};
//API must be enabled before use.
//https://developers.google.com/apps-script/advanced/sheets
Sheets.Spreadsheets.Values.update(request, ss.getId(), request.range, {
valueInputOption: 'USER_ENTERED',
});
或者循环遍历:
data = data.map(function(e){return [e];});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)