简体   繁体   English

在 Google Sheets Arrayformula 中将递增的行号与字符串连接起来

[英]Concatenate incrementing row number with string in Google Sheets Arrayformula

I'm trying to get a column to automatically fill up with incrementing strings depending on the row number in an ARRAYFORMULA in Google sheets.我试图让一列自动填充递增字符串,具体取决于 Google 表格中ARRAYFORMULA中的行号。 I can easily get a column to show a shifted row number by putting =ARRAYFORMULA(ROW(A:A)-1) in the top cell.通过将=ARRAYFORMULA(ROW(A:A)-1)放在顶部单元格中,我可以轻松地获得一列来显示移位的行号。 However trying to use this ROW call inside CONCATENATE does not give me the result I want, I've tried with and without TO_TEXT .但是,尝试在CONCATENATE中使用此ROW调用并没有给我想要的结果,我尝试过使用和不TO_TEXT

In the image the formula used for the different columns are:在图像中,用于不同列的公式是:

A1: =ARRAYFORMULA(ROW(A:A)-1) A1: =ARRAYFORMULA(ROW(A:A)-1)

B1: =ARRAYFORMULA(IF(ROW(B1:B)>1,CONCATENATE("Hello World: ",(ROW()-1)),"Hello there world!")) B1: =ARRAYFORMULA(IF(ROW(B1:B)>1,CONCATENATE("Hello World: ",(ROW()-1)),"Hello there world!"))

C1: =ARRAYFORMULA(IF(ROW(C1:C)>1,CONCATENATE("Hello World: ",TO_TEXT(ROW(C:C)-1)),"Hello there world!")) C1: =ARRAYFORMULA(IF(ROW(C1:C)>1,CONCATENATE("Hello World: ",TO_TEXT(ROW(C:C)-1)),"Hello there world!"))

D1:D16: Manually entered the desired strings. D1:D16:手动输入所需的字符串。

Spreadsheet screen shot电子表格屏幕截图

As you can see, B1 doesn't increment the number, only uses the ROW value from the cell where the formula is given.如您所见, B1不会增加数字,仅使用给出公式的单元格中的ROW值。 And C1 concatenates all the numbers of the rows into every line. C1将所有行数连接到每一行。

Any ideas on how I can accomplish the intended result without filling or using scripts?关于如何在不填充或使用脚本的情况下实现预期结果的任何想法?

there is an unwritten rule that says to never use CONCATENATE unless you really need it which is also always never.有一条不成文的规则说,除非你真的需要它,否则永远不要使用CONCATENATE ,这也是永远不会的。 to join stuff all you need is &加入所有你需要的东西是&

=ARRAYFORMULA({"Hello there world!"; "Hello World: "&ROW(A2:A)-1})

In B1 try在 B1 尝试

=ARRAYFORMULA(IF(ROW(B:B)>1, "Hello World: "&ROW(B:B)-1,"Hello there world!"))

or或者

={"Hello there world!"; ARRAYFORMULA("Hello World: "&ROW(B2:B)-1)}

and see if that works?看看这是否有效?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM