我在Google文档中创建了一个书签。我知道书签Id。
function addBookmark() {
var doc = DocumentApp.getActiveDocument();
var cursor = doc.getCursor();
var bookmark = doc.addBookmark(cursor);
var bookmarkId = bookmark.getId();
Logger.log(bookmarkId);
}
答案 0 :(得分:0)
书签ID无效。更好的是在文档中写一个带有特定文本的段落。现在,您可以搜索它并添加或更新图像。
function updateImageAtParagraph() {
var body = DocumentApp.getActiveDocument().getBody();
// Get an image in Drive from its ID.
var image = DriveApp.getFileById('...imageId...');
var searchString = "paragraphText"; //specific text paragraph in the document
var paragraphSearch = body.findText(searchString);
if(paragraphSearch !== null) {
var paragraph = paragraphSearch.getElement().getParent().asParagraph();
paragraph.clear().appendText(searchString);
paragraph.appendInlineImage(image);
}
}