如何访问快捷方式所指向的Google工作表? [英] How to access to the google sheet the short cut ist pointing at?

查看:73
本文介绍了如何访问快捷方式所指向的Google工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[![在此处输入图片描述] [1]] [1]我已经制作了Google表格的快捷方式(Google的新功能).

[![enter image description here][1]][1]I have made a shortcut (new feature of google) of a google sheets.

现在,我想获取目录中所有的电子表格:这些功能不再适用于处理所有电子表格: folder.getFilesByType(mimeType),因为引入了新"快捷方式,即新的mime类型.
快捷方式的ID与原始文件不同.您将无法再通过目录中找到的文件的ID来访问.

Now I want to get all the Spreadsheets I have in a directory: these function does not work anymore to treat all the Spreadsheet: folder.getFilesByType(mimeType) because the 'new' shortcut a new mime type has been introduced.
The ID of the shortcut is different from the original file. You can not access anymore over ID of the files you find in the directory.

  1. 仅选择电子表格和电子表格的解决方案是什么目录中的快捷方式?
  2. 如何打开快捷方式所指向的电子表格?

    function myFunction() {
      var ss=SpreadsheetApp.getActiveSheet();
      var idRepertoire=ss.getRange("A1").getValue();

      var monRep=DriveApp.getFolderById(idRepertoire);

      var fichiers=monRep.getFiles();


      while (fichiers.hasNext()) {
        var fichier=fichiers.next();
        var parentFichiers=fichier.getParents();
        while (parentFichiers.hasNext()){
          var parent=parentFichiers.next();
          var identiteF=fichier.getId();
          ss.appendRow([fichier.getName(),fichier.getMimeType(),identiteF,parent.getName()]);
          SpreadsheetApp.openById(identiteF).getSheetName("test").getRange("A1"); // causes an error for the shortcut
        }
      }

    }


  [1]: https://i.stack.imgur.com/grcin.png

推荐答案

您的两个问题都可以通过使用 Drive API 来解决.

Both of your questions can be solved by using the Drive API.

为了检索所有电子表格和电子表格快捷方式,您可以使用 GET 请求检索文件:

In order to retrieve all the spreadsheets and the spreadsheet shortcuts, you can use the GET request to retrieve the files:

  • 对于电子表格类型:
GET https://www.googleapis.com/drive/v3/files

对于 q 字段

mimeType = 'application/vnd.google-apps.spreadsheet'

  • 对于快捷方式类型:
  • GET https://www.googleapis.com/drive/v3/files
    

    对于 q 字段

    mimeType = 'application/vnd.google-apps.shortcut'
    

    此后,如果要从上述快捷方式中检索文件,则只需为每个快捷方式执行 GET 请求.因此,对于一个快捷方式,您可以执行以下操作,其中 fileId 实际上是快捷方式的 id .

    Afterwards, if you want to retrieve the files from the shortcuts above, you can simply do a GET request for each shortcut. So for one shortcut, you can do something like this, where fileId is in fact the id of the shortcut.

    GET  https://www.googleapis.com/drive/v3/files/fileId
    

    对于 字段 字段

    shortcutDetails
    

    在此 GET 请求之后,您将收到响应,您可以在其中找到快捷方式的 mimeType 以及原始的 id 快捷方式中文件的名称.

    After this GET request, you will receive a response in which you can find the mimeType of the shortcut as well as the original id of the file from the shortcut.

    {
     "shortcutDetails": {
      "targetId": "ID_OF_THE_ORIGINAL_FILE",
      "targetMimeType": "MIME_TYPE_OF_THE_ORIGINAL_FILE"
     }
    }
    
    

    参考

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