google-apps-script - Google Script - 如何将文档图像附加在一起?
问题描述
我有以下用于将文档附加在一起的代码块。它工作正常,但每当它尝试附加包含图像的文档时,它都会抛出异常“不允许操作”。关于为什么的想法受到赞赏。
var docIDs = destFolder.getFiles();
while (docIDs.hasNext()) {
var file = docIDs.next();
list.push(file.getId());
}
var baseDoc = DocumentApp.openById(list[0]);
var body = baseDoc.getActiveSection();
for (var i = 1; i < list.length; ++i ) {
var otherBody = DocumentApp.openById(list[i]).getActiveSection();
var totalElements = otherBody.getNumChildren();
for( var j = 0; j < totalElements; ++j ) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.INLINE_IMAGE )
body.appendImage(element);
else if( type == DocumentApp.ElementType.PAGE_BREAK )
body.appendPageBreak(element);
else if( type == DocumentApp.ElementType.PARAGRAPH )
body.appendParagraph(element);
}
}
编辑:抛出错误的确切行是 else if( type == DocumentApp.ElementType.PARAGRAPH ) body.appendParagraph(element);
我试图附加在一起的文档是包含一些图像的简单 Google DOC。
解决方案
推荐阅读
- c# - 更改 3DS 模型的颜色和透明度
- python - 查找多个图像的平均值
- python - KivyMD 卡内图像的圆角
- javascript - 如何为 curried 函数添加额外的级别?
- apache-tika - 在 StormCrawler 中使用 Apache Tika 进行语言检测
- amazon-web-services - 如何连接 Amazon ECR 网站与 Route53 连接
- javascript - electronjs应用程序异步/等待不等待函数返回数据
- reactjs - 我无法获得每个调度工作的索引
- reactjs - 如何对时间进行排序并以正确的顺序显示消息
- tailwind-css - Webpack + postcss 没有清除 Tailwind