原生 Google 表格中的嵌套 'for' 循环(无脚本)
Nested 'for' loops in native Google Sheets (no scripts)
我知道可以通过以下方式在 Google 表格中模拟 for 循环:
=ARRAYFORMULA(IF(LEN({range_0 to iterate over}),{function_0 for each element in range_0}))
我一直无法扩展上述方法来实现多嵌套for循环的效果。这可能吗?理想情况下,这看起来像:
=ARRAYFORMULA(IF(LEN({range_0 to iterate over}),IF(LEN({range_0.1 to iterate over for each parent element in range_0}),{function_0.1 for each element in range_0.1},{OPTIONAL: function_0 for each element in range_0})))
示例应用程序:
为一列中的每一行迭代一行中的每个单元格(见下文;我确信有办法通过其他方法实现此效果,但我已将请求和指定的方法用于单个动态公式的情况需要跟上未知和不断变化的行数、列数和所涉及的函数):
原始数据:
Thing
Type
Feature
Cost
Apple
Fruit
Seeds
Car
Automobile
Wheels
,000
Laptop
Computer
Keyboard
0
Grape
Fruit
Tastiness
[=15=].50
理论公式:
=ARRAYFORMULA(IF(LEN(`Thing`),IF(LEN(COLUMNS({current row of `Thing`})),{current cell in current row of `Thing`} & " of column " & COLUMN({*current cell*}) & " and row " & ROW(`Thing`),""),""))
以上理论公式输出:
Thing
Type
Feature
Cost
Apple of column 1 and row 3
Fruit of column 2 and row 3
Seeds of column 3 and row 3
of column 4 and row 3
Car of column 1 and row 4
Automobile of column 2 and row 4
Wheels of column 3 and row 4
,000 of column 4 and row 4
Laptop of column 1 and row 5
Computer of column 2 and row 5
Keyboard of column 3 and row 5
0 of column 4 and row 5
Grape of column 1 and row 6
Fruit of column 2 and row 6
Tastiness of column 3 and row 6
[=16=].50 of column 4 and row 6
感谢您的帮助!
尝试:
=ARRAYFORMULA(IF(LEN(A3:E7), A3:E7&" of column "&COLUMN(A3:E7)&" and row "&ROW(A3:E7), ))
我知道可以通过以下方式在 Google 表格中模拟 for 循环:
=ARRAYFORMULA(IF(LEN({range_0 to iterate over}),{function_0 for each element in range_0}))
我一直无法扩展上述方法来实现多嵌套for循环的效果。这可能吗?理想情况下,这看起来像:
=ARRAYFORMULA(IF(LEN({range_0 to iterate over}),IF(LEN({range_0.1 to iterate over for each parent element in range_0}),{function_0.1 for each element in range_0.1},{OPTIONAL: function_0 for each element in range_0})))
示例应用程序: 为一列中的每一行迭代一行中的每个单元格(见下文;我确信有办法通过其他方法实现此效果,但我已将请求和指定的方法用于单个动态公式的情况需要跟上未知和不断变化的行数、列数和所涉及的函数):
原始数据:
Thing | Type | Feature | Cost |
---|---|---|---|
Apple | Fruit | Seeds | |
Car | Automobile | Wheels | ,000 |
Laptop | Computer | Keyboard | 0 |
Grape | Fruit | Tastiness | [=15=].50 |
理论公式:
=ARRAYFORMULA(IF(LEN(`Thing`),IF(LEN(COLUMNS({current row of `Thing`})),{current cell in current row of `Thing`} & " of column " & COLUMN({*current cell*}) & " and row " & ROW(`Thing`),""),""))
以上理论公式输出:
Thing | Type | Feature | Cost |
---|---|---|---|
Apple of column 1 and row 3 | Fruit of column 2 and row 3 | Seeds of column 3 and row 3 | of column 4 and row 3 |
Car of column 1 and row 4 | Automobile of column 2 and row 4 | Wheels of column 3 and row 4 | ,000 of column 4 and row 4 |
Laptop of column 1 and row 5 | Computer of column 2 and row 5 | Keyboard of column 3 and row 5 | 0 of column 4 and row 5 |
Grape of column 1 and row 6 | Fruit of column 2 and row 6 | Tastiness of column 3 and row 6 | [=16=].50 of column 4 and row 6 |
感谢您的帮助!
尝试:
=ARRAYFORMULA(IF(LEN(A3:E7), A3:E7&" of column "&COLUMN(A3:E7)&" and row "&ROW(A3:E7), ))