如何将多维数组连接成格式化字符串

huangapple go评论51阅读模式
英文:

How to concatenate a multiple dimensional array into a formatted string

问题

给定一个包含2列和x行的Excel数组/表/数据透视表:

A B
项目1 10
项目2 20
... ...
项目x 9999

是否有一个数组公式可以创建以下文本字符串结果(可能使用concatenate和textjoin的组合,或者类似于scan的东西,允许对数组中的项目运行lambda函数?)

项目1 (10),项目2 (20),... (...),项目x (9999)

我知道可以添加另一列来连接值,然后对该列进行textjoin,但我正在寻找一个可以在一个公式中完成所有操作的解决方案,因为我相信Excel可以做到,而且这是一个更方便的解决方案。

英文:

Given an Excel array/table/pivot table with 2 columns and x rows:

A B
Item1 10
Item2 20
... ...
Itemx 9999

Is there an array formula that allows to create the following text string result (potentially using a combination of concatenate and textjoin, or something like scan that allows running a lambda for items in an array?)

> Item1 (10), Item2 (20), ... (...) , Itemx (9999)

I do know its possible to add another column that concatenates the values and then textjoin that column, but I'm looking for a solution that does it all within a formula because I believe Excel can do it and it's a more convenient solution.

答案1

得分: 3

如何将多维数组连接成格式化字符串

使用简单的TEXTJOIN公式似乎非常直观。

=TEXTJOIN(", ",FALSE,A1:A5&" ("&B1:B5&")")
英文:

如何将多维数组连接成格式化字符串

It seems quite straight-forward with a simple TEXTJOIN formula.

=TEXTJOIN(", ",FALSE,A1:A5&" ("&B1:B5&")")

答案2

得分: 0

I can help you with the Chinese translation of the provided content. Here it is:

"这里(Excel 模板)/ 下面是参考。

(无需使用 lambda 函数)...

=LET(x_,B2:C6,y_,TEXTJOIN("",1,IF(--ISNUMBER(x_),"("&x_&"), ",x_)),MID(y_,1,LEN(y_)-2))

如何将多维数组连接成格式化字符串"

英文:

Here (excel template)/below refer.

(no lambdas required)...

=LET(x_,B2:C6,y_,TEXTJOIN("",1,IF(--ISNUMBER(x_),"("&x_&"), ",x_)),MID(y_,1,LEN(y_)-2))

如何将多维数组连接成格式化字符串

答案3

得分: 0

你可以尝试使用以下代码:

=TEXTJOIN(", ",1,
BYROW(A1:B4,LAMBDA(x,
CHOOSECOLS(x,1)&"("&CHOOSECOLS(x,2)&")"))
)

如何将多维数组连接成格式化字符串

英文:

You may try-

=TEXTJOIN(", ",1,
BYROW(A1:B4,LAMBDA(x,
CHOOSECOLS(x,1)&"("&CHOOSECOLS(x,2)&")"))
)

如何将多维数组连接成格式化字符串

huangapple
  • 本文由 发表于 2023年4月17日 05:10:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030346.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定