使用Google Apps脚本将Google Drive图像插入文档 [英] Inserting a Google Drive image into a document using Google Apps Script

查看:357
本文介绍了使用Google Apps脚本将Google Drive图像插入文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在文档中插入图像。我可以通过一个带有诸如这样的URL http://www.geeks-on-wheels.net/wp-content/uploads/apple.jpg 。试图使用位于我的Google云端硬盘上的图片时出现问题。该网址如下所示: https:// docs.google.com/a/finance-in-motion.com/file/d/0B5sPSMZ9pf-QMG9GOVROakxQYmM/edit https://docs.google.com/a/finance-in-motion.com/file/d/0B5sPSMZ9pf -QMG9GOVROakxQYmM /编辑?USP =共享。该脚本似乎不知道如何处理它,并引发错误。任何帮助将不胜感激。



问候,



Shawn

驱动器托管



插入使用内置的apis来读取文件的博客并插入img。



这是一个从我的驱动器(或者我可以访问的文件)中插入jpg到文档的示例。

 函数insertImageFromDrive(){
var fileId ='0B_dyIOzoasdfasdfPVTMxdTVXWDg';
var img = DriveApp.getFileById(fileId).getBlob();
DocumentApp.getActiveDocument()。getBody()。insertImage(0,img);
}

这会在文档的顶部插入图片。要更好地控制光标/选择替换,请参阅此博客文章


I am trying to pro grammatically insert an image into a document. I can get this to work fine with an image with a URL such as http://www.geeks-on-wheels.net/wp-content/uploads/apple.jpg. The problem comes when trying to use an image located on my Google Drive. The URL looks like this https://docs.google.com/a/finance-in-motion.com/file/d/0B5sPSMZ9pf-QMG9GOVROakxQYmM/edit or https://docs.google.com/a/finance-in-motion.com/file/d/0B5sPSMZ9pf-QMG9GOVROakxQYmM/edit?usp=sharing. The script doesn't seem to know what to do with it and throws an error. Any help would be appreciated.

Regards,

Shawn

解决方案

To insert files from Drive do not use the HTTP route unless the file has been made public via drive hosting

Insert use the built in apis to read the file's blog and insert the img.

Here is an example of inserting a jpg from my drive (or a file I have access to) to a document.

function insertImageFromDrive(){
 var fileId = '0B_dyIOzoasdfasdfPVTMxdTVXWDg';
 var img = DriveApp.getFileById(fileId).getBlob();
 DocumentApp.getActiveDocument().getBody().insertImage(0, img); 
}

This will insert an image at the top of the document. To get more control over the cursor/selection replacement see this blog post.

这篇关于使用Google Apps脚本将Google Drive图像插入文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆