Google Apps 脚本 - 将内联绘图从一个文档复制到另一个文档
Google Apps Scripts - Copy Inline Drawing from One Document to Another
我正在尝试将整个文档从一个文档复制到另一个文档。
我只是想将 INLINE_DRAWING 从一个 google 文档复制到另一个文档,但我一直收到此错误。如果我删除附加绘图的尝试,则没有错误,但在我完成的文档中没有绘图。您如何正确地将内联绘图从一个文档复制到另一个文档?
// fromFile & toFile are objects after calling .getBody()
function copyFileContentsFromTo(fromFile,toFile){
for(var i=0; i<fromFile.getNumChildren();i++){ //run through the elements of the template doc's Body.
var child = fromFile.getChild(i);
switch (fromFile.getChild(i).getType()) { //Deal with the various types of Elements we will encounter and append.
case DocumentApp.ElementType.PARAGRAPH:
// Look for child elements within the paragraph. Inline Drawings are children.
if(child.asParagraph().getNumChildren() !=0 && child.asParagraph().getChild(0).getType() == DocumentApp.ElementType.INLINE_DRAWING) {
console.log("Found an Inline Drawing");
var drawing = child.asParagraph();
toFile.append(drawing.copy()); // This causes the error!
}else{
toFile.appendParagraph(child.copy());
}
break;
case DocumentApp.ElementType.TABLE:
toFile.appendTable(child.copy());
break;
default:
console.log("Whoops. Did not handle this Element Type when Copy Data from Template to Main: " + fromFile.getChild(i).getType());
break;
}
}
}
我已经找遍了,找不到任何资源,这是最接近的,但在我的屏幕截图中仍然会产生错误:
在你的脚本中,需要修改如下。
发件人:
toFile.append(drawing.copy());
收件人:
toFile.appendParagraph(drawing.copy());
重要提示:
- 现阶段复制包含内嵌图的段落时,请关闭V8运行时。上述修改后的脚本与V8运行时一起使用时,会出现
Exception: Action not allowed
这样的错误。所以请注意这一点。这已在 Google 问题跟踪器中报告。 Ref我很乐意相信这个错误可以在未来的更新中被删除。
参考:
我正在尝试将整个文档从一个文档复制到另一个文档。
我只是想将 INLINE_DRAWING 从一个 google 文档复制到另一个文档,但我一直收到此错误。如果我删除附加绘图的尝试,则没有错误,但在我完成的文档中没有绘图。您如何正确地将内联绘图从一个文档复制到另一个文档?
// fromFile & toFile are objects after calling .getBody()
function copyFileContentsFromTo(fromFile,toFile){
for(var i=0; i<fromFile.getNumChildren();i++){ //run through the elements of the template doc's Body.
var child = fromFile.getChild(i);
switch (fromFile.getChild(i).getType()) { //Deal with the various types of Elements we will encounter and append.
case DocumentApp.ElementType.PARAGRAPH:
// Look for child elements within the paragraph. Inline Drawings are children.
if(child.asParagraph().getNumChildren() !=0 && child.asParagraph().getChild(0).getType() == DocumentApp.ElementType.INLINE_DRAWING) {
console.log("Found an Inline Drawing");
var drawing = child.asParagraph();
toFile.append(drawing.copy()); // This causes the error!
}else{
toFile.appendParagraph(child.copy());
}
break;
case DocumentApp.ElementType.TABLE:
toFile.appendTable(child.copy());
break;
default:
console.log("Whoops. Did not handle this Element Type when Copy Data from Template to Main: " + fromFile.getChild(i).getType());
break;
}
}
}
我已经找遍了,找不到任何资源,这是最接近的,但在我的屏幕截图中仍然会产生错误:
在你的脚本中,需要修改如下。
发件人:
toFile.append(drawing.copy());
收件人:
toFile.appendParagraph(drawing.copy());
重要提示:
- 现阶段复制包含内嵌图的段落时,请关闭V8运行时。上述修改后的脚本与V8运行时一起使用时,会出现
Exception: Action not allowed
这样的错误。所以请注意这一点。这已在 Google 问题跟踪器中报告。 Ref我很乐意相信这个错误可以在未来的更新中被删除。