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 🙏

© 2025 – Pkg Stats / Ryan Hefner

google-sheets-data-fetcher

v1.1.7

Published

Fetch data from one or multiple google sheets, without any API key.

Downloads

39

Readme

google-sheets-data-fetcher

Version

Fetch data from one or multiple google sheets, without any API key.

Highlights

  • no api key required
  • fetch multiple sheets and/or "sub sheets" at once
  • output as json objects or csv
  • write data to separate output files
  • 2 usages:
    • as classical package/dependency
    • via cli/command line
  • small package size ( < 40kB )
  • written in typescript
  • tested via Jest

Introduction

lib-intro-on-youtube

Installation

For cli / command line usage

If you want to use the google-sheet-data-fetcher as a command line tool you have 2 options - you can either use it directly via npx or install it globally on your system.

npx

npx google-sheets-data-fetcher [options]

global install

Via npm:

npm i -g google-sheets-data-fetcher

Via yarn:

yarn global add google-sheets-data-fetcher

For classical package / dependency usage

Just install via npm...

npm i google-sheets-data-fetcher --save

... or for yarn use:

yarn add google-sheets-data-fetcher

Usage

First of all, you need to determine a google sheet's ids, simply by looking at its URL.

Example URL:

In this example URL, the part that is underlined in green, would be the main sheet id, while the blue part would be the currently viewed "sub sheet" id.

Use these kind of id's according to your desired outcomes (command line fetch, etc. - details below).

For cli / command line usage

If you installed it for cli usage as described above, you can afterwards just use it on the command line by typing gsdf (short for google-sheet-data-fetcher), followed by appropriate options. To see available options, type gsdf --help, or check the following table:

| Argument | Required? | Description | example | | ------------------------ | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | -s <sheet-ids> | yes | The -s argument must be followed by one main sheet id (required, corresponding to the green part in the example URL above) and can also be followed by additional "sub sheet" ids, separated by ,. The resulting <ids> value must be one continuous string. | -s abcde,0,468,11111This argument would target one google sheet (via abcde) and 3 of its sub sheets. Note how there's no space between the individual ids. | | -f <output-format> | yes | The -f argument represents the desired output format, which can be one of JSON_RAW, JSON_COLUMNS, JSON_ROWS, CSV. Note that for the cli usage you can only provide one of these at a time (as opposed to in dependency usage, see further below). Details regarding output formats can be found below. | -f JSON_COLUMNS | | -o <output-file-names> | no | The -o argument is optional and represents the desired output file name. Similarly to the -s flag above you can provide multiple output file names by separating them with , - and in case you provide multiple (sub) sheets, you also have to - in other words, the number of fetched (sub) sheets must correspond to the number of provided file names. | -o 1stSheet.json,2ndSheet.json |

Getting data from multiple google sheets at once

The -s and -o flags above can be provided multiple times, in case you need to fetch data from multiple google sheets at once.

Example: gsdf -f JSON_COLUMNS -s 19VnV0Hu0IcwkIqUJndKeUNSSne2OvpLKSSccDiHPmw4,0,1086688112 -s 197U_3ZQaL7jN0sPZvKPhQRN-1tKfwr_VXL09b8W5zpI -o a1.json,a2.json -o b.json

For package / dependency usage

Import the main function like so:

import { fetchGoogleSheetsData } from "google-sheets-data-fetcher";

You can then use the fetchGoogleSheetsData function by providing 2 arguments, where the 1st describes the sheets to be fetched, and the second one describes the desired output format(s).

Example:

const result = fetchGoogleSheetsData(
  // 1st argument:
  [
    {
      sheetId: "19VnV0Hu0IcwkIqUJndKeUNSSne2OvpLKSSccDiHPmw4", // from the example URL above
      subSheetsIds: [
        "0",
        "1086688112", // from the example URL above
        "2100601117",
      ],
      outputFileDestinations: [
        "./1stSubSheet.json",
        "./2ndSubSheet.json",
        "./3rdSubSheet.json",
      ],
    },
    {
      sheetId: "197U_3ZQaL7jN0sPZvKPhQRN-1tKfwr_VXL09b8W5zpI",
      subSheetsIds: ["0", "201058147"],
      outputFileDestinations: ["./firstSubSheet.json", "./secondSubSheet.json"],
    },
  ],
  // 2nd argument:
  ["JSON_COLUMNS"]
);

According to the 1st argument the example above would fetch data from 2 Google Sheets at once, and will also fetch the individual "sub sheets" accordingly, because the subSheetIds are being provided. You can also omit this prop - in that case it would only fetch the first sub sheet's data, which always corresponds to "0".

The optional prop outputFileDestinations will allow you to not only retrieve the data within the function's return value (as shown here, to be stored in const result) but also write the data to separate json files. If you provide this prop, you need to make sure, that the number of provided output file names exactly matches the number of (sub)sheets to be fetched. Also make sure, that you are not re-using certain filenames, as this would lead to overwriting files.

In the 2nd argument you need to specify an array of one or multiple desired output formats.

Details regarding output formats can be found below.

If you provide more than one desired output format, the return value will be an object, holding the desired multiple formats, like so:

const outputFormats = ["JSON_COLUMNS", "JSON_ROWS"];
// ...
// => result:
// {
//   JSON_COLUMNS: { ... data in column oriented format ... },
//   JSON_ROWS: { ... data in row oriented format ... }
// }

Output formats

"JSON_RAW"

interface RawFormat {
  reqId: string;
  sig: string;
  status: string;
  table: {
    cols: { id: string; label: string; type: string }[];
    rows: { c: { v: string }[] }[];
  };
}

"JSON_COLUMNS"

interface ColumnFormat {
  [columnKey: string]: {
    id: string;
    label: string;
    type: string;
    rows: {
      [rowKey: string]: { id: number; data: string };
    };
  };
}

"JSON_ROWS"

interface RowFormat {
  [rowKey: string]: {
    id: number;
    columns: {
      [columnKey: string]: {
        id: string;
        label: string;
        type: string;
        data: string;
      };
    };
  };
}

"CSV"

, as cell separators,

" as cell value holders

and newlines \n as data entry separators