Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add images to Google Document via Google Apps Script

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

like image 350
ehfeng Avatar asked Oct 26 '11 03:10

ehfeng


1 Answers

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.

like image 142
Eduardo Avatar answered Sep 23 '22 06:09

Eduardo