使用应用程序脚本将Google Drive中的文件加载到表单中 [英] Load File from Google Drive into a form using apps script

查看:176
本文介绍了使用应用程序脚本将Google Drive中的文件加载到表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我想使用应用程序脚本创建表单。然后我们要从Google Drive加载文件到这个表单中。

b $ b

然而,直到现在,我仍然没有任何从驱动器加载文件的功能。



感谢您在这种情况下的帮助。
Thanks,
KN

解决方案

如果我理解你的问题,我想你想加载将(ny)文件的内容插入表单上的小部件。不幸的是,使用GAS构建UiApp是不可能的。

您可以显示图像和纯文本文件以及其他几种类型,但不能 all 文件。

如果您尝试显示html文件,则只能看到文本。没有图片,没有链接等。

  //允许的HTML标签列表:
// B,BLOCKQUOTE ,BODY,BR,CENTER,CAPTION,CITE,CODE,DIV,EM,
// H1,H2,H3,H4,H5,H6,HR,I,LABEL,LEGEND,LI,OL,P,SPAN ,
// STRONG,SUB,SUP,TABLE,TBODY,TD,THEAD,TITLE,TR,TT,UL

发生这种情况是因为Caja剥夺了其他所有人。



在最近一直试图做同样的事情,但我最终以'beter do别的东西'。

所以我决定创建一个包含可变文件的文件,并为每个文件创建一个锚点。这样做,用户可以点击一个文件并打开它。



如果您想引用驱动器上的文件,您可以创建包含

的链接

  var driveUrl ='https://drive.google.com/uc?export=view&id='; 

并将其与fileId结合为 urlFile 对于一个锚点。

  var row = 0; 
var flxTable = app.createFlexTable();
var files = DriveApp.getFiles();
while(files.hasNext())
{
var file = files.next();
var fileId = file.getId();
var fileName = file.getName();
var urlFile = driveUrl + fileId;
var anchor = app.createAnchor(fileName,urlFile);
flxTable.setWidget(row ++,0,anchor);
}

可能你会有太多的文件使用上面的代码来显示它们它只需要很长时间才能加载),所以你必须小心只显示当时看到所需的文件,然后加载其他文件。


Currently, I want to buld a form using apps script. Then we want to load the file from Google Drive into this form.

All result will be showed in the form as a link.

However, until now, I still don't have any function for loading file from drive.

I appreciate your helps on this case. Thanks, KN

解决方案

If I understand your question well, I think you want to load the CONTENTS of a(ny) file into a widget on a form.

Unfortunally, using GAS for building an UiApp this is not possible.
You can show images and plain textfiles and several other types, but not all files.
If you try to show html-files, you will only see texts. No pictures, no links etc.

//   list of HTML tags that are permitted:
//     B, BLOCKQUOTE, BODY, BR, CENTER, CAPTION, CITE, CODE, DIV, EM, 
//     H1, H2, H3, H4, H5, H6, HR, I, LABEL, LEGEND, LI, OL, P, SPAN,
//     STRONG, SUB, SUP, TABLE, TBODY, TD, THEAD, TITLE, TR, TT, UL     

This occurs because Caja strips out everythings else.

In have been trying to do the same (recently) but I ended up with 'beter do something else'.
So I decided to create a flextable containing files and I created an anchor for each file. Doing that, the user can click on a file and it opens.

If you want to refer to files on the drive you can create links containing

 var driveUrl = 'https://drive.google.com/uc?export=view&id=';

and combine this with the fileId to urlFile for an anchor.

   var row = 0;
   var flxTable = app.createFlexTable();
   var files    = DriveApp.getFiles();
   while (files.hasNext())
   {
      var file     = files.next();
      var fileId   = file.getId();
      var fileName = file.getName();
      var urlFile  = driveUrl + fileId;
      var anchor   = app.createAnchor(fileName, urlFile);
      flxTable.setWidget(row++, 0, anchor);
   }

Probably you will have far too many files to show them using the code above (it just takes too long to load), so you have to take care just showing files that are required to see at that time and load others afterwards.

这篇关于使用应用程序脚本将Google Drive中的文件加载到表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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