javascript - 如何在 Office 插件中插入外部图像?
问题描述
我想使用以下方法将图像插入到 PowerPoint 幻灯片setSelectedDataAsync
中Office.CoercionType.Image
:
Office.context.document.setSelectedDataAsync(image, {
coercionType: Office.CoercionType.Image,
imageLeft: 5,
imageTop: 5,
imageWidth: 100,
imageHeight: 100
});
该系统适用于资产,我只需将图像插入画布,然后将其转换为数据 URL:
const image = new Image();
image.src = props.url;
ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
然后我们只需将画布插入幻灯片:
var cvs = canvas.current;
var result = cvs.toDataURL().split(",")[1];
Office.context.document.setSelectedDataAsync(result, {
coercionType: Office.CoercionType.Image,
imageLeft: 5,
imageTop: 5,
imageWidth: canvas.current.width / 3,
imageHeight: canvas.current.height / 3
});
问题是该系统不适用于外部图像。我收到错误“SecurityError”,因为一旦在画布中插入外部图像,clean-origin 标志就会设置为 false。如何插入外部图像?
谢谢你。
解决方案
这是在 Office 加载项中插入图像的教程。
推荐阅读
- excel - 可以在数组公式中使用 INDIRECT 或替代方法来引用封闭的外部工作簿吗?
- android - 专注于 AutoCompleteTextView 在 Android TV 设备上不显示软键盘
- excel - 我的 VBA excel 代码在 Mac Excel 上运行,但不在 Windows Excel 2016 上运行
- laravel - 在 Laravel 中通过多对多关系模型对 eloquent 模型进行排序
- javascript - 自定义操作以编辑行覆盖其他操作
- sql - 在 PostgreSQL 中创建嵌套的 json blob
- java - 无法检测和安装所选平台。java 或 javac 可能无法执行
- swift - 如何在 Xcode 中的 git ignore 中添加故事板画布方向
- c++ - 范围使用声明,在标头内
- azure-devops - 使用 Azure DevOps 部署 Mulesoft 应用程序