Import tabular data packages (http://data.okfn.org/doc/data-package) into Google Spreadsheets
To import a tabular data pacakage into Google Spreadsheets:
- Go to https://docs.google.com/spreadsheet/ccc?key=0AqR8dXc6Ji4JdG15Z1BhNXpCMFBnVTY5LUpoTGNrY0E#gid=0
- Make a copy of the sheet
- Go to Data Packages Menu -> Import Data (on the first run, you will be asked for authorization)
- Paste in the url: http://data.okfn.org/data/house-prices-us/datapackage.json
- Watch the data load!
Note: You can replace the datapackage.json url with any other tabular data package link
A small script is included in the spreadsheet. This in turn uses a library (the code from this repository) that loads and processes CSV data from the data package.
To use the script in your own spreadsheets:
-
In your spreadsheet open the script editor to create a new script
-
Include the library. To do this:
- Go to Resources => Manage Resources
- Use the project id: MH6zwb-fUDq8QyPrl-PbJlu_4T1jeIs
- Make sure that the latest version is selected
- More information on using libraries can be found here: https://developers.google.com/apps-script/guide_libraries#useLibrary
-
Copy and paste the following into your script and hit save:
function onOpen() {
DataPackages.onOpen();
}
function importDataPackageUi() {
DataPackages.importDataPackageUi();
}
- Hit run
- There is now a new Data Packages menu in your spreadsheet. Whenever you open the spreadsheet in the future it will be there.
Currently, the library can cope with a single CSV file from a tabular data package. The field separator should be a comma, the text delimiter should be "
and the line separator should be \n
. That means we're not yet fully conformant with the specification, but this will hopefully be achieved soon via a more general API that pre-processes the data according to format and dialect.
The contents of the file library.gs.js
should replace the code here:
https://script.google.com/macros/d/1GLuZPrroyUP4WkHm4aAT4Z2QUqoL60LhEJnomYZT7nzaMDjptOneTNdJ/edit
The contents of the file linking_code.gs.js
need to be placed in the spreadsheet script, and the README.md
(this file) updated accordingly.