繁体   English   中英

Google文件-使用Google Apps脚本在书签上创建图像

[英]Google Docs - create image at bookmark with Google Apps Script

我已经在Google文档中创建了一个书签。 我知道书签ID。

function addBookmark() {
 var doc = DocumentApp.getActiveDocument();
 var cursor = doc.getCursor();
 var bookmark = doc.addBookmark(cursor);

 var bookmarkId = bookmark.getId();

 Logger.log(bookmarkId);  
}
  1. 我可以在书签的Google Drive中创建图像吗?
  2. 创建图像后,我想使用基于时间的触发器定期对其进行更新。 我必须先删除图像,还是可以不删除而更新它?

书签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);
 }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM