如何在Google表格中合并具有相同索引且具有不同值的行?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Google表格中合并具有相同索引且具有不同值的行?相关的知识,希望对你有一定的参考价值。

我有一个电子表格,其中包含一个名为uniqueStyle和多列的索引。 uniqueStyle有多个sizeprimaryImg-src。我想要折叠他们拥有相同uniqueStyle的行,每个大小和img-src在它自己的单元格中。

这是我的例子:

uniqueStyle   dressTitle      size        imageSrc
CH1506        Lace Bodice Sateen Sheath Dress   
CH1506                              S   
CH1506                              M   
CH1506                              L   
CH1506                              XL  
CH1506                              2X  
CH1506                              3X  
CH1506                                              /image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506_2_.jpg
CH1506                                              /image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506.jpg
CH1506                                              /1/image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506_3_.jpg
CH1506                                                  /1/image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506_4_.jpg

得到的输出结果:

uniqueStyle         dressTitle                      size                imageSrc
CH1506              Lace Bodice S..                 S        /image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506_2_.jpg
CH1506                                              M        /image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506.jpg
CH1506                                              L        /1/image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506_3_.jpg
CH1506                                              XL       /1/image/1000x1500/9df78eab33525d08d6e5fb8d27136e95/c/h/ch1506_4_.jpg
CH1506                                              2X  
CH1506                                              3X                                          

(抱歉,无法在此处正确对齐文本。)

答案

通过一些简单的查询,您可以保留甚至订单:

=Original!A1:F1; ARRAYFORMULA(ARRAY_CONSTRAIN(SORT(IF(ISERROR(VALUE(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0))), (QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0), 
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)), IF(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)<>"", VALUE(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0), 
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)), )), 1, 1), 999^99, 4),
 QUERY(TO_TEXT(SORT(IF(ISERROR(VALUE(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0), 
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0))), (QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0), 
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)), IF(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)<>"", VALUE(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)), )), 1, 1, 5, 1)), "select Col5", 0),
 QUERY(SORT(IF(ISERROR(VALUE(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0))), (QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0), 
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)), IF(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)<>"", VALUE(QUERY(
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0), 
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0)), )), 1, 1), "select Col6", 0))

0

另一答案

如果您不需要保留订单,请执行以下操作:

=Original!A1:F1; ARRAYFORMULA(QUERY( 
 QUERY(TO_TEXT(Original!A2:D), "order by Col1", 0),
 QUERY(TO_TEXT(Original!A2:E), "select Col5 order by Col1,Col5 desc", 0),
 QUERY(TO_TEXT(Original!A2:F), "select Col6 order by Col1,Col6 desc", 0),
 "where Col5 is not null or Col6 is not null", 0))

0

另一答案
="uniqueID", "DressTitle", "dressDescription", "dressTags", "Size", "DressImgs"; 
 ARRAYFORMULA(QUERY(REGEXREPLACE(
 QUERY(SORT(IF(LEN(A2:A), IF(ISERR(VALUE(A2:A)), A2:A, VALUE(A2:A)), 
 IF(B2:D="", A2:A&"♠", A2:A&"♦"&B2:D), ), 1, 1), "select *"),
 QUERY(SORT(IF(LEN(A2:A), IF(ISERR(VALUE(A2:A)), A2:A, VALUE(A2:A)), E2:E, 
 IF(E2:E="", A2:A&"♠", A2:A&"♦"&E2:E), ), 1, 1, 2, 1), "select Col3"),
 QUERY(SORT(IF(LEN(A2:A), IF(ISERR(VALUE(A2:A)), A2:A, VALUE(A2:A)), F2:F, 
 IF(F2:F="", A2:A&"♠", A2:A&"♦"&F2:F), ), 1, 1, 2, 1), "select Col3"),
 "(.*)♠|(.*)♦", ""), "where Col5 is not null or Col6 is not null"))

0

以上是关于如何在Google表格中合并具有相同索引且具有不同值的行?的主要内容,如果未能解决你的问题,请参考以下文章

如何在不合并索引的情况下连接具有不同多索引的两个数据帧?

如何在 Python 中合并多个具有不同表格列的 Excel 工作表?

将具有相同列/索引的两个 pandas DataFrame 合并为一个 DataFrame

如何通过Python合并具有相同名称但在不同文件夹中的文件的内容?

您如何建议合并具有相同属性但值类型不同的接口

将具有相同 id 的行合并为一行,保留所有数据