B
B
bmw_man8602020-06-01 15:33:21
Google Apps Script
bmw_man860, 2020-06-01 15:33:21

How do I import data from a text file that is saved daily to Google Drive?

Good afternoon. Help with script. Every day, a TXT file YYYY-MM-DDn.TXT is stored in Google Drive. How can I use a script to find this file and import data from it into an existing table with an existing sheet called dd.mm.yyyy? The date in the file name and the sheet name are the same, but are written in different formats. You need to import daily in automatic mode. Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2020-06-01
@bmw_man860

Make a function, hang it on a time trigger (daily). In the function:
1) Open a file iterator with a specific name

var fileIterator = DriveApp.getFilesByName(fileName);

2) Get the contents of the file(s):
while(fileIterator.hasNext()){
  var textFromFile = fileIterator.next().getAs(ContentService.MimeType.TEXT);
};

3) Write data where necessary
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(name).getRange(row, column).setValue(textFromFile );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question