You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Sheets中实现多列表格交叉连接(无需脚本或字符串拼接)

Google Sheets 实现多列表格的Cross Join(笛卡尔积)

我会发布自己的答案,但为了帮助有类似需求的人并鼓励其他方案,特此提问。

有时我需要将两个表格进行cross join(即生成第一个表格的每一行与第二个表格的每一行的所有组合)。例如,假设有一个包含参赛厨师及其菜品的表格,和一个包含评审员及其专长属性的表格(以下为可直接粘贴到Google Sheets的公式形式):

table1 = {
  { "Albion"    , "Artichoke Soufflé Omelett" };
  { "Burgess"   , "Lemony Braised Chicken" };
  { "Hamad"     , "Mabo Dofu Smoothie" };
  { "Berengari" , "Chicken-Fried Plantains" };
  { "Sengupta"  , "Smoky Vegan Corn Salad" }
}

table2 = {
  { "Cho"       , "flavor" };
  { "Nikkelson" , "texture" };
  { "Rodríguez" , "process" }
}

那么这两个表格的cross join结果有15行,开头部分如下:

output = {
  { "Albion"    , "Artichoke Soufflé Omelett" , "Cho"       , "flavor" }
  { "Albion"    , "Artichoke Soufflé Omelett" , "Nikkelson" , "texture" }
  { "Albion"    , "Artichoke Soufflé Omelett" , "Rodríguez" , "process" }
  { "Burgess"   , "Lemony Braised Chicken"    , "Cho"       , "flavor" }
  { "Burgess"   , "Lemony Braised Chicken"    , "Nikkelson" , "texture" }
  { "Burgess"   , "Lemony Braised Chicken"    , "Rodríguez" , "process" }
  ...
}

核心要求

需要实现该功能的公式或命名函数,需满足以下条件:

  • 不使用Google Apps Script
  • 避免“字符串拼接法”:即禁止将数组序列化为带特殊分隔符的字符串,经文本操作拼接后再反序列化为目标数组的方法。这类方法存在诸多问题:数值转字符串时会产生副作用;若数据包含特定表情符号,可能出现不可预测的行为;同时代码难以排查和维护。

相关问题说明

我的问题与以下三个问题类似,但它们仅针对单列表格的cross join:

  • Generate all possible combinations for Columns(cross join or Cartesian product)
  • How to cross join 2 lists?
  • Google sheets - cross join / cartesian join from two separate columns

有一个旧问题虽未明确提及多列表格,但示例数据包含多列,不过提问者允许使用Apps Script:

  • How to perform Cartesian Join with Google Scripts & Google Sheets?

另有一个问题可能类似,但因提问者未附示例数据且链接表格已失效,无法确认:

  • Google Sheets Cross Join Function Tables with More than Two Columns

内容的提问来源于stack exchange,提问作者garcias

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 23:10:52