0
votes

I am using this Script to import a 10 column, 100k row zipped .txt file into google sheets. It works.

var url = "url goes here" 
var zipblob = UrlFetchApp.fetch(url).getBlob(); 
var unzipblob = Utilities.unzip(zipblob); 
var unzipstr=unzipblob[0].getDataAsString();
var csv = Utilities.parseCsv(unzipstr);

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
ss.getRange(1, 1, csv.length, csv[0].length).setValues(csv);

I would like to filter it so it only imports rows where the value in column 4 contains the string "2021" example values for this column are "Apr 24 2018 12:00 AM" and "2019-01-28 0:00:00" it switches between formats.

I have tried filtering by date hoping it would somehow work but that was fruitless.

Anyone know how?

1

1 Answers

1
votes

Use filter and check if it includes 2021:

var url = "url goes here" 
var zipblob = UrlFetchApp.fetch(url).getBlob(); 
var unzipblob = Utilities.unzip(zipblob); 
var unzipstr=unzipblob[0].getDataAsString();
var csv = Utilities.parseCsv(unzipstr);
var f_csv = csv.filter(r=>r[3].includes("2021") || r[3].includes("-02-"));

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
ss.getRange(1, 1, f_csv.length, f_csv[0].length).setValues(f_csv);