问题
I want to know if it is possible and if so how I can achieve converting an array of 8 columns and 300+ rows into a sorted, concatenated, one-dimensional array where each row is the concatenation of the contents in the 8 columns. I would also like to achieve this using a single formula.
Example:
leg | dog | tom | jon | bar | | | |
foo | bin | git | hub | bet | far | day | bin |
...
would convert into:
bar dog jon leg tom
bet bin bin day far foo git hub
...
I can achieve this for a single row using this:
=arrayformula(CONCATENATE(transpose(sort(transpose(F2:M2),1,1))&" "))
as long as the 8 columns are from F to M I can then copy this formula down 300+ times which is easy to do but I would like a single formula that populates n number of rows.
Can this be achieved or do I have to copy the formula down?
回答1:
Something like this should do that:
=transpose(split(" "&join(" ",index(sort(arrayformula({row(A1:A300),len(A1:A300)*0-9E+99
;row(A1:A300),A1:A300
;row(A1:A300),B1:B300
;row(A1:A300),C1:C300
;row(A1:A300),D1:D300
;row(A1:A300),E1:E300
;row(A1:A300),F1:F300
;row(A1:A300),G1:G300
;row(A1:A300),H1:H300
})),0,2))," "&-9E+99&" ",false))
First it creates a two-dimensional array with original row number in the first column and value in the second for each cell (adding a new value -9e99 for each row), then the array is sorted, first column is discarded, all values are joined using a space, then split (by the added value surrounded by spaces), and finally transposed.
回答2:
If I understood correctly, you should be able to do that with a formula like this
=ArrayFormula(transpose(query(transpose(A2:H8),,50000)))
Change the range to suit. See also below picture.
EDIT: An alternative way may be to create a custom formula (sorting included). Add this to the script editor
function concatenateAndSort(range) {
return range.map(function (r) {
return [r.sort().join(" ")]
})
}
Then in the spreadsheet (where you want the output to appear) enter
=concatenateAndSort(A3:H8)
(Change range to suit).
回答3:
=A2&" "&B2&" "&C2&" "&D2&" "&E2&" "&F2&" "&G2&" "&H2
=JOIN(" "; A2:H2)
SORTED ROW: =TRANSPOSE(SORT(TRANSPOSE(JOIN(" ";A2:H2));1;TRUE))
AND THEN: CTRL+SHIFT+⇩ DOWN ARROW ... CTRL+ENTER
来源:https://stackoverflow.com/questions/41847717/google-sheets-concatenate-a-2d-array-into-a-single-column-and-sort-simultaneousl