Add images to Google Document via Google Apps Scri

2019-01-17 17:36发布

How can you add images to a Google Document (not Spreadsheet or Presentation) via Google Apps Script. I don't see an addImage method. Surely the team would not have left this out.

http://code.google.com/googleapps/appsscript/class_document.html

1条回答
放荡不羁爱自由
2楼-- · 2019-01-17 18:20

From the docs:

function insertImage() {
  // Retrieve an image from the web.
  var resp = UrlFetchApp.fetch("http://www.google.com/intl/en_com/images/srpr/logo2w.png");

  // Create a document.
  var doc = DocumentApp.openById("");

  // Append the image to the first paragraph.
  doc.getChild(0).asParagraph().appendInlineImage(resp.getBlob());
}

http://code.google.com/googleapps/appsscript/class_documentapp_listitem.html#appendInlineImage

I'm not sure if you can upload an image. But you sure can insert it into a Paragraph via a url.

查看更多
登录 后发表回答