【问题标题】:Google Drive Picker ViewId.SPREADSHEET showing spreadsheets and forms显示电子表格和表单的 Google Drive Picker ViewId.SPREADSHEET
【发布时间】:2018-01-01 09:38:38
【问题描述】:

有没有办法将 Google 云端硬盘选择器仅限于电子表格。我正在添加电子表格视图 ID(根据 Google 文档中的以下脚本),但是它同时显示了表格和表单。

function createPicker(token) {
  if (pickerApiLoaded && token) {
    var picker = new google.picker.PickerBuilder()
        // Instruct Picker to display only spreadsheets in Drive. For other
        // views, see https://developers.google.com/picker/docs/#otherviews
        .addView(google.picker.ViewId.SPREADSHEETS)
        // Hide the navigation panel so that Picker fills more of the dialog.
        .enableFeature(google.picker.Feature.NAV_HIDDEN)
        // Hide the title bar since an Apps Script dialog already has a title.
        .hideTitleBar()
        .setOAuthToken(token)
        .setDeveloperKey(DEVELOPER_KEY)
        .setCallback(pickerCallback)
        .setOrigin(google.script.host.origin)
        // Instruct Picker to fill the dialog, minus 2 pixels for the border.
        .setSize(DIALOG_DIMENSIONS.width - 2,
            DIALOG_DIMENSIONS.height - 2)
        .build();
    picker.setVisible(true);
  } else {
    showError('Unable to load the file picker.');
  }
}

【问题讨论】:

    标签: google-apps-script google-drive-api


    【解决方案1】:

    我认为你可以通过setting the MIME 类型来做到这一点。 MIME 类型可以在here. 找到

    PickerBuilder.setSelectableMimeTypes(string)
    

    【讨论】:

    • 谢谢杰森。这确实限制了可选择的文件类型,但我更喜欢根本不显示表单。科斯的回答允许这样做。不过感谢您的回复。
    【解决方案2】:

    首先,创建一个视图(注意view.setMimeTypes):

    // Instruct Picker to display only spreadsheets in Drive. For other
    // views, see https://developers.google.com/picker/docs/#otherviews
    var view = new google.picker.DocsView(google.picker.ViewId.SPREADSHEETS);
    view.setMimeTypes('application/vnd.google-apps.spreadsheet');
    view.setIncludeFolders(true);
    

    然后添加视图到选择器:

    var picker = new google.picker.PickerBuilder().addView(view)
    

    【讨论】:

    • 谢谢科斯,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多