任何方式以编程方式分享谷歌文档

任何方式以编程方式分享谷歌文档

本文介绍了任何方式以编程方式分享谷歌文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以从融合表中获取数据,并将其放入Google文档(使用我制作的模板),将其制作为pdf并显示链接(以PDF形式)。我的问题是,它对我的​​帐户正常工作,但如果有其他人试图点击它,他们会不断收到404未找到错误。我的猜测是错误出现,因为我是唯一一个被允许查看文件的人。我的问题是:有没有一种方法可以与组织中的每个人以编程方式共享文件,或者有另一种方法可以做到这一点? 解决方案

p>您可以使用 DocsList.addViewers(viewersEmails [])



来完成此操作。

  function addviewers(viewers){//查看者列表作为参数,将它们添加为查看者并发送包含链接的电子邮件。在CSV 
var viewerssArray = viewers.replace(/,/g,\",\").split(\",\");//这个'替换'中删除任何可能存在的空格在字符串
Logger.log(viewersArray.length +':'+ viewersArray);
var file = DocsList.getFileById('您的文档ID')。addViewers(viewersArray);
var docurl = file.getUrl();
for(nn = 0; nn< viewersArray.length; ++ nn){
MailApp.sendEmail(viewersArray [nn],'your document',docurl);


我首先使用'editor'作为变量名称,现在更改为查看者以避免混淆。



如果您确实需要在域中包含所有人才能访问,我想最好的解决方案是创建一个包含所有用户的组来简化流程。



编辑:也许有一种更简单的解决方案,即将文件移入共享文件夹:文件夹中的所有项目与文件夹本身具有相同的共享参数。



示例:

  function sharebyFolder(){
var file = DocsList.getFileById('docId');
var folder = DocsList.getFolderById('shared folder Id');
file.addToFolder(folder)
}


I have a program that will get data from a fusion table, put it in a google doc(using a template I made), make it a pdf and then display a link to it(to the pdf). My problem is that it works fine for my account but if anyone else tries to click on it they keep getting the "404 Not Found" error. My guess is that the error shows up because I am the only one allowed to view the file. My question is: Is there a way to programmatically share the file with everyone in the organization or is there another way to do it?

解决方案

You can do it using DocsList.addViewers(viewersEmails[])

here is an example that takes a list of viewers as parameter, add them as viewers and sends an email with the link :

function addviewers(viewers) { // pass emails as a string in CSV
  var viewerssArray = viewers.replace(/, /g,",").split(",");// the 'replace' is there to remove any spaces that could be in the string
  Logger.log(viewersArray.length+'  :  '+viewersArray);
  var file = DocsList.getFileById('your doc ID').addViewers(viewersArray);
  var docurl=file.getUrl();
      for (nn=0;nn<viewersArray.length;++nn){
        MailApp.sendEmail(viewersArray[nn], 'your document', docurl);
          }
}

I first used 'editor' as variable name, now changed to 'viewers' to avoid confusion.

If you really need to include everybody in your domain to get access I guess the best solution would be to create a group with all users to simplify the process.

EDIT : there is maybe a simpler solution that is to move the file in a shared folder : all items in a folder have the same sharing parameters as the folder itself.

example :

function sharebyFolder(){
    var file = DocsList.getFileById('docId');
    var folder = DocsList.getFolderById('shared folder Id');
    file.addToFolder(folder)
      }

这篇关于任何方式以编程方式分享谷歌文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:02