javascript - 是否可以在 Google Doc 中的图像前添加换行符?
问题描述
目前检索这样的图像:
var body = DocumentApp.getActiveDocument().getBody();
var styles = {};
styles[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;
var imgs = body.getImages();
imgs[0].getParent().setAttributes(styles);
我可以添加一些属性来在图像之前放置换行符吗?或者也许获取图像的索引并添加换行符。
提前致谢。
解决方案
关于Is there some attribute I can add to place line breaks before image?
,不幸的是,我找不到直接实现您的目标的属性。所以在这种情况下,我想提议maybe get the index of image and add line breaks.
。当这反映到脚本时,它变成如下。
示例脚本:
var body = DocumentApp.getActiveDocument().getBody();
var image = body.getImages()[0];
var index = body.getChildIndex(image.getParent());
body.insertParagraph(index, "\n")
- 运行脚本时,会在 Google 文档正文中的第一张图片之前插入换行符。
笔记:
- 例如,在内联图像后添加换行符时,可以使用
DocumentApp.getActiveDocument().getBody().getImages()[0].getParent().asParagraph().appendText("\n")
.
参考:
推荐阅读
- asynchronous - 过滤输出流以仅保留由特定行分隔的部分文本?
- python - RabbitMQ Pika Python 客户端 - 树莓派零 W
- python - 尝试递归打印基于 Python 中的算术级数的模式
- c# - 将每个下方的按钮设置为面板
- oracle - How to edit a nclob column using Sql Developer
- linux - 在 Linux 下使用 Casadi 的 Octave 无法加载 liboctinterp.so
- java - 如何从 Firestore 获取数组内的地图值?
- blockchain - 加密货币中的“空投”一词是什么意思?
- regex - 具有多个条件的正则表达式 js。没有用 html 标记(跨度)包围的文本的第一个条件和用花括号包围的第二个条件
- c# - 在 C# 实体查询中检索左连接表的总和