Posts

Showing posts from April, 2023

Unzipping a csv file and pasting the data into a Google sheet

 This little script is just an example of how to retrieve a zip file (by url), unzip the file, and copy/paste the data to a Google sheet tab overwriting whatever is there. function   fetchData () {    var   ss  =  SpreadsheetApp . getActiveSpreadsheet ();    var   sheet  =  ss . getSheetByName ( "derivatives" )    var   url  =  "https://archives.nseindia.com/content/historical/DERIVATIVES/2023/JAN/fo03JAN2023bhav.csv.zip"    var   zipblob  =  UrlFetchApp . fetch ( url ). getBlob ();    var   unzipblob  =  Utilities . unzip ( zipblob );    var   unzipstr  =  unzipblob [ 0 ]. getDataAsString ();    var   csv  =  Utilities . parseCsv ( unzipstr );    sheet . getRange ( 'A7:O' ). clearContent ();    sheet . getRange ( 6 ,  1 ,  csv . length ,  csv [ 0 ]. length ). setValues ( csv ); }