1

Similar to this, I wish to read data stored in csv format in a GitHub repository directly into Google sheets.

An example of the data in question is here. When I tell google sheets to import the (raw) data from this url, it finds no matching file: enter image description here.

Can a direct import be achieved this simply, or does it necessarily involve using an API?

emagar
  • 985
  • 2
  • 14
  • 28

2 Answers2

3

In your situation, how about the following patterns?

Pattern 1:

In this pattern, IMPORTDATA is used. A sample formula is as follows. Please put this formula into a cell of Spreadsheet.

=IMPORTDATA("https://raw.githubusercontent.com/emagar/elecRetrns/master/data/pred1964-on.csv")

Pattern 2:

In this pattern, Google Apps Script is used. Please copy and paste the following script to the script editor of Spreadsheet and run the script. By this, the retrieved CSV data is put into the active sheet.

function myFunction() {
  // Retrieve CSV data and parse it.
  const url = "https://raw.githubusercontent.com/emagar/elecRetrns/master/data/pred1964-on.csv";
  const str = UrlFetchApp.fetch(url).getContentText();
  const ar = Utilities.parseCsv(str);

  // Put the values into the active sheet.
  const sheet = SpreadsheetApp.getActiveSheet(); // or SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1")
  sheet.getRange(1, 1, ar.length, ar[0].length).setValues(ar);
}

References:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
1

If you have to do that only once, this can be helpful - Have you tried the following steps:

  1. Copy and paste the data from Here to notepad
  2. Save the notepad file as xyz.csv
Yashasvi
  • 36
  • 3
  • This two-step solution works perfectly. But I wish to know if files can be directly imported/read from GitHub into Google sheets. – emagar Feb 18 '23 at 19:02