【问题标题】:Add images to Google Document via Google Apps Script通过 Google Apps 脚本将图像添加到 Google 文档
【发布时间】:2011-10-26 03:38:02
【问题描述】:

如何通过 Google Apps 脚本将图像添加到 Google 文档(不是电子表格或演示文稿)。我没有看到 addImage 方法。团队肯定不会遗漏这一点。

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

【问题讨论】:

    标签: google-docs google-apps-script


    【解决方案1】:

    来自文档:

    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

    我不确定您是否可以上传图片。但是您肯定可以通过 url 将其插入到段落中。

    【讨论】:

    • 我可以用 PNG 来做到这一点,但由于某种原因不能用 JPEG。我为此提交了错误报告。
    • @Frederic - 我让它适用于所有格式。见example here
    • @Eduardo - 有关通过表单将图像上传到文档的示例,请参阅其他评论。
    • @Sergeinsas 我从未更新我的评论,但后来我意识到这是因为文件大小。我调整了所有照片的大小,从那以后就再也没有遇到过问题。
    猜你喜欢
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 2022-07-02
    • 2019-09-04
    相关资源
    最近更新 更多