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

如何通过单条Slack消息借助Zapier向Excel添加多行数据

问题解决:从Slack单条消息提取多行数据到Excel

你的问题出在原脚本只维护了一个数据字典,所有内容都合并到同一组里,自然只能输出一行。要实现多组数据提取,核心是识别每组数据的分隔(消息里两组之间是连续空行),每遇到分隔就把当前组的数据存入结果,然后开始新的一组。

修改后的Python脚本

# 获取输入的Slack消息内容
message = input_data["Message"]

# 按换行拆分所有行
lines = message.split("\n")

# 初始化输出列表(用来存多组数据)
output = []
# 初始化当前组的数据字典
current_data = {}

for line in lines:
    stripped_line = line.strip()
    # 处理空行:如果是空行且当前组已有数据,说明一组数据结束
    if stripped_line == "":
        if current_data:  # 只有当前组有内容时才存入
            output.append(current_data)
            current_data = {}  # 重置字典,准备存下一组
        continue
    
    # 拆分键和值(按第一个冒号分割)
    if ":" not in stripped_line:
        # 处理Description的多行内容(没有冒号的行属于上一个Description)
        if "Description" in current_data:
            current_data["Description"] += "\n" + stripped_line
        continue
    
    key, value = stripped_line.split(":", 1)
    key = key.strip()
    value = value.strip()
    
    if key == "Description":
        # 处理Description的多行拼接
        if key in current_data:
            current_data[key] += "\n" + value
        else:
            current_data[key] = value
    else:
        current_data[key] = value

# 把最后一组数据加入输出(因为最后一组后面没有空行)
if current_data:
    output.append(current_data)

# 输出结果给Zapier
return {"output": output}

关键改动说明

  • 新增current_data字典专门存当前组的内容,每完成一组就存入output列表并重置
  • 遇到空行时判断是否要结束当前组(避免空行被误判)
  • 处理Description的多行内容:如果行里没有冒号,就自动追加到上一个Description的值里
  • 循环结束后手动加入最后一组数据(因为最后一组后面没有触发空行判断)

Zapier后续配置注意

在Zapier的Excel「添加行」步骤中,需要开启Line Item Mode(在步骤设置里找「Use Line Items」选项),这样Zapier会自动遍历输出列表里的每一组数据,每一组对应Excel里的一行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 19:22:57