我正在编写一个函数,通过将每个元素都移动到一个新文档中来复制当前的文档--它是一个更大项目的一部分。
但是,当文档中有脚注时,函数就会失败,出现此错误。
Service Documents failed while accessing document with id [id of target doc]
现在,我对不能将脚注转换为新文件的功能没有问题--或者至少只传递脚注的文本。但是,此错误会阻止我的整个函数运行(文档中的任何元素都不会被转移)。
是否可以忽略脚注或将脚注转换为文本,并允许函数将所有其他元素转换为新文档?
,这是我的代码:
function duplicateDocument() {
var currentDoc = DocumentApp.getActiveDocument().getBody();
var targetDoc = DocumentApp.create('New Doc');
var totalElements = currentDoc.getNumChildren();
//Goes through each type of element to preserve formatting
for( var index = 0; index < totalElements; ++index ) {
var body = targetDoc.getBody();
var element = currentDoc.getChild(index).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE){
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM){
body.appendListItem(element);
} else if( type == DocumentApp.ElementType.BOOKMARK ){
body.appendBookmark(element);
} else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
body.appendImage(element);
} else if( type == DocumentApp.ElementType.HORIZONTAL_RULE ){
body.appendHorizontalRule();
} else if( type == DocumentApp.ElementType.PAGE_BREAK ){
body.appendPageBreak();
}
}
}
发布于 2020-07-23 10:00:36
不幸的是,在现阶段,用Apps脚本编程创建脚注是不可能的
样本:
if( type == DocumentApp.ElementType.PARAGRAPH){
var num = element.asParagraph().getNumChildren();
for( var i = 0; i < num; i++ ) {
var child = element.asParagraph().getChild(i);
var childType = child.getType();
if( childType == DocumentApp.ElementType.FOOTNOTE){
child.removeFromParent();
}
}
body.appendParagraph(element);
}
https://stackoverflow.com/questions/62973123
复制相似问题