npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spreadsheetjs

v0.0.2

Published

A simple Javascript API to work with public Google spreadsheets

Downloads

8

Readme

SpreadsheetJS

A simple Javascript API to work with public Google spreadsheets

TODO write tests

Usage

Spreadsheet usage

To retrieve a spreadsheet, you simply create an instance of the Spreadsheet class:

import { Spreadsheet } from 'spreadsheetjs';

const spreadsheet = new Spreadsheet('<hash>', '<key>');

hash is the hash identifier of your spreadsheet and key is your Google API key which the library will use to authenticate with Google.

Before you can use the spreadsheet, you'll have to load it's meta data so it's aware of which sheets and spreadsheet it should use. The spreadsheet will automatically load it's own meta data, but to be sure you have access to the meta data it exposes a wait function, which returns a Promise instance.

spreadsheet.wait().then((spreadsheet) => {
	// You can use your spreadsheet here.
});

To list all available sheets in a spreadsheet, you can use the sheets property of the spreadsheet

const sheets = spreadsheet.sheets;

You will notice the sheets property returns an array of strings; to retrieve the actual sheet for processing, you'll have to use the sheet method

spreadsheet.sheet('<name>').then((sheet) => {
	// You can use your sheet here.
});

If you omit the name parameter, it'll default to the first sheet.

Sheet usage

Once you retrieved your sheet instance from the spreadsheet, things really get interesting!

The sheet class exposes two properties; name and data. As you can guess, the name property is the name of the sheet, and the data is the raw data from the Google API that the spreadsheet manipulates internally to work it's magic.

If you want to read a cell from the sheet, you can use the read function

const value = sheet.read('A1');

As you can see, you can pass in Excell coordinates as you're used to working with.

Obviously one cell at a time is tedious to work with, so let's say you want to read cell B1 to G5

const values = sheet.range('B1', 'G5');

this will return a 2 dimensional array that could look something like this:

[
	['B1', 'B2', 'B3', 'B4', 'B5'],
	['C1', 'C2', 'C3', 'C4', 'C5'],
	['D1', 'D2', 'D3', 'D4', 'D5'],
	['E1', 'E2', 'E3', 'E4', 'E5'],
	['F1', 'F2', 'F3', 'F4', 'F5'],
	['G1', 'G2', 'G3', 'G4', 'G5'],
]

An empty row will be returned as an empty array ([]) following the Google API's example.

Of course you can use the range function to retrieve columns and rows, but it's easier to use the respective column and row function for that, as they return flat arrays rather than 2 dimensional arrays

const column = sheet.column('B'); // returns the B column
const row = sheet.row('3'); // returns the third row

But what if you don't want the entire row, or the entire column? We got you, pass in a second parameter to skip some parts;

const column = sheet.column('B', '5'); // returns the B column starting on row 5
const row = sheet.row('3', 'C'); // returns the third row starting from column C

Available commands

  • npm run build

    • builds the sources
  • npm test

    • runs all the available tests
  • npm test -- watch

    • runs all the available tests and re-runs them on changes.