在段落的特定点插入图像 [英] insert image at specific point of paragraph
本文介绍了在段落的特定点插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
*我有一个带有类似text {logo} text"的字符串的 Google 文档如何将图像放置在 {logo} 所在的位置?到目前为止,我尝试过:
*I have a Google Document with a string like "text {logo} text" How do place an image where {logo} is? So far I tried:
var logoElement = s.findText("{logo}").getElement();
logoElement.getParent().insertInlineImage(0,logoBlob);
s.replaceText("{logo}", "");
但是这会在找到的段落之前插入图像(或带有 1:after).我如何将它放在段落中的确切位置?
But this inserts the image before the found paragraph (or with 1: after). How do I place it inside the paragraph at the exact location?
推荐答案
希望能帮到你,下面的代码对我来说没问题.
I hope will be helpful, The following code is fine to me.
function insertImage(doc) {
// Retrieve an image from the web.
var resp = UrlFetchApp.fetch("http://www.google.com/intl/en_com/images/srpr/logo2w.png");
var image = resp.getBlob();
var body = doc.getBody();
var oImg = body.findText("<<Logo1>>").getElement().getParent().asParagraph();
oImg.clear();
oImg = oImg.appendInlineImage(image);
oImg.setWidth(100);
oImg.setHeight(100);
}
这篇关于在段落的特定点插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文