Giter VIP home page Giter VIP logo

get-sheet-done's Introduction

GetSheetDone

Helper library to pull data from google spreadsheets.
Live demo: https://giladaya.github.io/get-sheet-done/

Caveats

This is a simple library intended to provide a quick-and-dirty way to only read data from a Google spreadsheet.
The document you read from must be publicly published for this to work and the entire sheet data is fetched.
If you need something more sophisticated, take a look at the Google Sheets API

Usage

Preparation

  • In the spreadsheet, file -> publish to web
  • Note the document key in the URL

In browser

See /example/src for a simple browser-based demo.
Make sure to include the the dependecy fetch-jsonp in the page.

With a package loader

Install from npm:

npm install --save get-sheet-done

Use in code:

import GetSheetDone from 'get-sheet-done';

GetSheetDone.raw(DOC_KEY).then(sheet => {
    console.log(sheet)
})

Api

There are three functions that return a promise and fetch the data from a published spreadsheet.
Each function gets as arguments the document key (from the document url) and optinally the sheet index (first sheet has index 1).
The functions differ in the way they parse and return the data:

Raw

GetSheetDone.raw(id, sheetNum = 1)

Get the data as a raw array of arrays (rows). Suitable for spreadsheets that only contain values.

Example

This sheet:

A B C D
1 22 24 26 20
2 31 32 37 36
3 11 14 19 12

Will result in this data:

{
  title: "Sheet1",
  updated: "2017-07-30T07:11:40.056Z",
  data: [
    ["22", "24", "26", "20"],
    ["31", "32", "37", "36"],
    ["11", "14", "19", "12"],
  ]
}

Labeled Columns

GetSheetDone.labeledCols(id, sheetNum = 1)

Get the data as an array of objects, each representing a row. The keys are taken from the first row in the spreadsheet which is assumed to contain column headers.

Note that all labels are converted to lower case and the only non-alphanumeric characters that are kept are periods and hyphens, so if the original label was Lorem-ipsum dolor.sit:amet_blah, the result labels would be: lorem-ipsumdolor.sitametblah.

Example

This sheet:

A B C D
1 Q1 Q2 Q3 Q4
2 22 24 26 20
3 31 32 37 36
4 11 14 19 12

Will result in this data:

{
  title: "Sheet1",
  updated: "2017-07-30T07:11:40.056Z",
  data: [{
    q1: "22",
    q2: "24",
    q3: "26",
    q4: "20"
  },{
    q1: "31",
    q2: "32",
    q3: "37",
    q4: "36"
  },{
    q1: "11",
    q2: "14",
    q3: "19",
    q4: "12"
  }]
}

Labeled Columns and rows

GetSheetDone.labeledColsRows(id, sheetNum = 1)

Get the data as an object of objects, each representing a row. The first column in the spreadsheet is assumed to contain row headers, and the first row in the spreadsheet is assumed to contain column headers.

Note that all column labels are converted to lower case and the only non-alphanumeric characters that are kept are periods and hyphens, so if the original label was Lorem-ipsum dolor.sit:amet_blah, the result labels would be: lorem-ipsumdolor.sitametblah.
Row labels remain unchanged.

Example

This sheet:

A B C D E
1 Q1 Q2 Q3 Q4
2 UK 22 24 26 20
3 US 31 32 37 36
4 AU 11 14 19 12

Will result in this data:

{
  title: "Sheet1",
  updated: "2017-07-30T07:11:40.056Z",
  data: {
    UK: {
      q1: "22",
      q2: "24",
      q3: "26",
      q4: "20"
    },
    US: {
      q1: "31",
      q2: "32",
      q3: "37",
      q4: "36"
    },
    AU: {
      q1: "11",
      q2: "14",
      q3: "19",
      q4: "12"
    }
  }
}

Development

  1. Clone this repo
  2. npm install
  3. npm start
  4. Go to localhost:3000
  5. See package.json for other available scripts

get-sheet-done's People

Contributors

giladaya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.