K
K
KIRILL2019-03-04 14:47:21
Google Apps Script
KIRILL, 2019-03-04 14:47:21

Google Apps Script how to select only google spreadsheets?

It is necessary that the script takes all the Google tables that are on Google Drive (of which it takes: title, date of creation, author, link).
Now there are two problems:

  1. How to select only google spreadsheets?
  2. The creator of the document. It only outputs "DriveUser" at the moment.

How can I transform this code to get what I intended?
function fileInf() {
  currentSheet = SpreadsheetApp.getActiveSheet();
  var files = DriveApp.getFiles();
  i = 1;
  for (i = 1; i <= 1000; i++) {
    files.hasNext();
    var file = files.next();
    currentSheet.getRange("A" + i).setValue(file.getName());
    currentSheet.getRange("B" + i).setValue(file.getDateCreated());
    currentSheet.getRange("C" + i).setValue(file.getOwner());
    currentSheet.getRange("D" + i).setValue(file.getUrl());
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2019-03-04
@kmarfutkin

Perhaps the following selection for files will suit you better

var files = DriveApp.searchFiles('mimeType="application/vnd.google-apps.spreadsheet"');

Pro DriveUser. This is a system object, so you need to use one of its methods to get the information. For example,
...
file.getOwner().getEmail()
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question