微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否可以在Google文档中的图片之前添加换行符? 示例脚本:注意:参考文献:

如何解决是否可以在Google文档中的图片之前添加换行符? 示例脚本:注意:参考文献:

当前正在检索这样的图像:

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")

参考文献:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。