如何使用Google脚本将数组附加到Google表格列中

问题描述 投票:-2回答:1

var arr=["aaa","bbb","ccc"];我想将其附加到列B7:D7使用谷歌脚本到set B7 as "aaa" C7 as "bbb" and D7 as "ccc"

google-apps-script google-sheets
1个回答
0
投票

您有一个行数组。您想要将值设置为一列。使用“转置”从行数组创建列数组然后将值设置到列

ref

https://webapps.stackexchange.com/questions/95178/transposing-column-to-row

一列值在Apps脚本中表示为[['a'],['b'],['c']]。行表示为[['a','b','c']]。以下函数将一个转换为另一个:



function col2row(column) {
  return [column.map(function(row) {return row[0];})];
} 

function row2col(row) {
  return row[0].map(function(elem) {return [elem];});
}



© www.soinside.com 2019 - 2024. All rights reserved.