【发布时间】:2020-08-05 23:29:17
【问题描述】:
由于此topic 的答案,我可以将内容表单模板文档复制到另一个保存所有格式的文档。
但是当我在几个段落中添加一些图片时,结果文档将图片显示为图片徽标
问题是如何以这种方式正确复制图像?
【问题讨论】:
标签: google-apps-script google-docs
由于此topic 的答案,我可以将内容表单模板文档复制到另一个保存所有格式的文档。
但是当我在几个段落中添加一些图片时,结果文档将图片显示为图片徽标
问题是如何以这种方式正确复制图像?
【问题讨论】:
标签: google-apps-script google-docs
您需要调整您的 insert 方法以适应每种不同的元素类型...
一个例子可能是这样的:
function copyElementsByType() {
var sourceDoc = DocumentApp.openById('yyyy');
var targetDoc = DocumentApp.openById('xxxx');;
var bodyS = sourceDoc.getBody();
var otherBody = targetDoc.getBody()();
var elements = bodyS.getNumChildren()
for( var e=0;e<elements;e++) {
var element = otherBody.getChild(e).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.insertParagraph(e,element)}
else if( type == DocumentApp.ElementType.TABLE ){
body.insertTable(e,element)}
else if( type == DocumentApp.ElementType.LIST_ITEM ){
body.insertListItem(e,element)}
else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
body.insertImage(e,element)
} else {
throw new Error("check what to do with this type of element : "+type);
}
}
}
【讨论】: