在this code之后,我正在使用Google Apps脚本将文档模板附加到另一个文档。该模板具有项目符号列表,但是这些项目列表将在复制后丢失,而缩进将被正确保留。
代码:
var newDoc = DocumentApp.openById('anotherGoogleID');
var newDocBody = newDoc.getBody();
var templateBody = DocumentApp.openById('aGoogleID').getActiveSection();
// has bullets
var totalElements = templateBody.getNumChildren();
newDocBody.appendPageBreak();
for( var j = 0; j < totalElements; ++j ) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.PARAGRAPH )
newDocBody.appendParagraph(element);
else if( type == DocumentApp.ElementType.TABLE )
newDocBody.appendTable(element);
else if( type == DocumentApp.ElementType.LIST_ITEM )
newDocBody.appendListItem(element);
else
throw new Error("Unknown element type: "+type);
}
newDocBody.saveAndClose()
答案 0 :(得分:2)
我发现我可以使用它
newDocBody.appendListItem(listItem.getText()).setAttributes(element.getAttributes());
将其置于上下文中:(基于https://www.labnol.org/code/19892-merge-multiple-google-documents)
for( var j = 0; j < totalElements; ++j ) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.PARAGRAPH )
body.appendParagraph(element).setAttributes(element.getAttributes());
else if( type == DocumentApp.ElementType.TABLE )
body.appendTable(element).setAttributes(element.getAttributes());
else if( type == DocumentApp.ElementType.LIST_ITEM ){
var listItem = element.asListItem();
body.appendListItem(listItem.getText()).setAttributes(element.getAttributes());
}
答案 1 :(得分:0)
在this sample之后,我以这种方式修改了代码:
class MySerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = ('id','name', ...)
extra_kwargs = {
'name': {
'help_text': 'You help text here...'
}
}
现在正在创建一些项目符号,但将项目符号而不是字母圈起来。...