如何在Google表格中将多个Smart Chip合并至单个单元格?
按团队合并多个Smart Chip到单个单元格的解决方案
直接使用TEXTJOIN、INDEX/MATCH或VLOOKUP这类内置函数无法实现需求——这些函数只会提取Smart Chip的文本值(比如邮箱),而非保留Chip对象本身。要实现合并后仍保留Smart Chip格式,需借助Google Apps Script:
- 打开目标Google表格,点击菜单栏「扩展」→「Apps脚本」
- 替换默认代码为以下脚本(示例中姓名Smart Chip在A列、团队在B列,合并结果写入C列,可根据你的表格结构调整列索引):
function mergeTeamSmartChips() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const dataRange = sheet.getDataRange(); const values = dataRange.getValues(); const teamChipsMap = new Map(); // 按团队分组收集Smart Chip的富文本对象 for (let rowIdx = 1; rowIdx < values.length; rowIdx++) { const teamName = values[rowIdx][1]; // B列:团队名称 const chipCell = sheet.getRange(rowIdx + 1, 1); // A列:姓名Smart Chip所在单元格 const chipRichText = chipCell.getRichTextValue(); if (!teamChipsMap.has(teamName)) { teamChipsMap.set(teamName, []); } teamChipsMap.get(teamName).push(chipRichText); } // 将分组后的Smart Chip合并写入目标列(C列) let targetRow = 2; teamChipsMap.forEach((chips, team) => { const targetCell = sheet.getRange(targetRow, 3); const combinedRichText = SpreadsheetApp.newRichTextValue(); chips.forEach((chip, idx) => { if (idx > 0) { combinedRichText.appendText(", ").setTextStyle(SpreadsheetApp.newTextStyle().build()); } // 保留原Smart Chip的文本和样式 combinedRichText.appendText(chip.getText()).setTextStyle(chip.getTextStyle()); }); targetCell.setRichTextValue(combinedRichText.build()); targetRow++; }); }
- 保存脚本并运行,授权必要权限后,即可在目标列得到按团队合并、且保留Smart Chip格式的结果。
注意:目前Google表格的内置函数体系中,没有原生支持合并Smart Chip对象的功能,脚本是唯一可行的方案。
内容的提问来源于stack exchange,提问作者Ken
相关产品推荐
相关产品推荐

