Add images to Google Document via Google Apps Script

前端 未结 1 526
攒了一身酷
攒了一身酷 2020-12-08 22:50

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 th

相关标签:
1条回答
  • 2020-12-08 23:29

    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.

    0 讨论(0)
提交回复
热议问题