如何在Google电子表格中返回以逗号分隔的单元格区域字符串?

时间:2014-04-06 06:40:15

标签: google-apps-script google-sheets

我正在使用Google电子表格。我正在编写一个自定义函数,它接受一系列单元格作为参数,并返回一个字符串,该字符串为单元格的内容添加分隔逗号。

例如,我们有一个范围B1:B2,其中单元格B1包含"B1_contents",单元格B2包含"B2_contents"。该函数应返回"B1_contents, B2_contents"

如何使用google-apps javacript在Google电子表格中完成此操作?

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:2)

您可以尝试以下操作:

function rangeToStringSep(range, sep) {
  return range.toString().split(',').join(sep);
}

使用:

=rangeToStringSep(B1:B3; ", ")

<强>更新

function rangeToStringSep1(range, sep) {
  return range.join(sep);
}

enter image description here

答案 1 :(得分:1)

你试过这样的事吗?

function toCommaSepStrings(values){
  return values.toString();
}