I’m trying to get some data from the federal reserve and paste into my spreadsheet.
So here is my code
function myFunction() {
var response = UrlFetchApp.fetch("http://research.stlouisfed.org/fred2/data/TWEXMANL.txt");
a=response.getContentText();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var InputSheet = ss.getSheetByName("Sheet5");
InputSheet.getRange("E5:E5").setValue(a);
}
This code pastes all of the output into E5. I just want the data following the “Date” and “Value” pasted into 2 columns.
Can anybody help me with this? I’m sure it’s pretty simple for you guys.
Thanks.
Using a little string manipulation, this becomes very easy:
I start by taking off the little intro text. I then split the string into an array containing the rows of data. I split each row (a string) into an array as well. This gives me a array I can use
setValues()on at the bottom. Because this isn’t just one cell, I have to specific the exact width and height or it fails.If you’d like to see the data at any point in there, I recommend
Logger.log(splitData);