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

如何通过Power Automate获取的file content向Excel插入完整图片

解决方案

你当前报错的核心原因是误用了json()函数:outputs('Get_file_content')?['body']?['$content']本身就已经是纯base64字符串,不是JSON格式内容,用json()解析自然会抛出格式错误。

1. Power Automate 侧提取base64字符串

直接在Compose动作中填入如下表达式即可,不需要加任何外层函数:

outputs('Get_file_content')?['body']?['$content']

该表达式返回的就是你需要的、可直接传入Office Script的图片base64编码,无需额外拼接data:image/xxx;base64,前缀,Office Script的addImage接口原生支持纯base64内容输入。

2. Office Script 侧插入图片

编写如下脚本,设置一个字符串类型的入参接收base64内容即可:

function main(workbook: ExcelScript.Workbook, imageBase64: string) {
    const targetSheet = workbook.getActiveWorksheet();
    // 插入图片
    const insertedImage = targetSheet.addImage(imageBase64);
    // 按需调整图片位置、尺寸
    insertedImage.setLeft(20);
    insertedImage.setTop(20);
    insertedImage.setWidth(400);
}

之后在Power Automate的「运行脚本」动作中,把Compose输出的base64内容传入脚本的imageBase64参数即可完成图片插入。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 20:06:03