google-apps-script - 列表项目编号不会转移到新文档
问题描述
我正在创建一个函数,它将用户当前正在选择的文本从一个文档传输到另一个文档。
它在大多数情况下都可以正常工作,但是当我尝试传输列表项时,如图所示,列表项编号消失了。
传输到目标文档后,最后一张图像中的列表项现在看起来像这样。
有没有办法确保号码被转移,或者至少以有效的方式重新创建它们?谢谢!
最小可重现示例:
function sendToDoc() {
var currentDoc = DocumentApp.getActiveDocument().getSelection();
var targetDoc = DocumentApp.openByUrl(a different documents url);
var body = targetDoc.getBody();
//if you are selecting some text, this function will transfer your selection into the target document
if(currentDoc) {
var totalElements = currentDoc.getRangeElements();
//for each element in your selection
for( var index = 0; index < totalElements.length; ++index ) {
var element = totalElements[index].getElement().copy();
var type = element.getType();
//gets the element type and transfers it over to the target doc
if( type == DocumentApp.ElementType.PARAGRAPH ){
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE){
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM){ //this is where the list items get transferred
body.appendListItem(element);
}
else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
body.appendImage(element);
}
else if( type == DocumentApp.ElementType.HORIZONTAL_RULE ){
body.appendHorizontalRule();
}
else {
}
}
}
解决方案
将字形类型设置为NUMBER
:
body
.appendListItem(element)
.setGlyphType(DocumentApp.GlyphType.NUMBER)
推荐阅读
- android - 如何在 React Native 中使用模拟位置 - Android
- php - 从电子邮件 woocomerce 中删除特定字段
- python - 将 30 天添加到现有的日期时间列 MYSQL Python
- javascript - 到达路由器更改 URL,不更新视图
- javascript - onclick 事件以不同方式执行相同的功能
- unity3d - 是否有可能在 Unity 3D 中获得良好的阴影?
- python - 如何获取到本地主机的 HTTP 请求?
- python-3.x - 将数据从 csv 文件插入到 mongodb
- mysql - MySQL - utf8 字符无法在 Web 前端正确显示
- c++ - 无法使用 openssl 服务器,因为密码已过时...或其他...ERR_SSL_VERSION_OR_CIPHER_MISMATCH