javascriptgoogle-sheetsgoogle-drive-apigoogle-drive-picker

Google Drive Picker ViewId.SPREADSHEET showing spreadsheets and forms


Is there a way to limit the Google Drive picker to spreadsheets only. I am adding the spreadsheet view id (per the below script from Google's documentation), however it is showing both Sheets and Forms.

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.');
  }
}

Solution

  • First, create a view (note 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);
    

    then add the view to the picker:

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