在段落的特定点插入图像
问题描述:
*我有一个带有类似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);
}