1.5.4 • Published 9 days ago

public-google-sheets-parser v1.5.4

Weekly downloads
90
License
MIT
Repository
github
Last release
9 days ago

Public Google Sheets Parser

Author checks npm package codecov license JavaScript Style Guide Hits GitHub stars downloads JSDelivr CDN

Introduction

Demo Page (click here)

Introduction

The Public Google Sheets Parser is a zero-dependency library that enables the use of publicly shared Google Sheets as a data source, akin to a database. Ensure your Google Sheet is public and formatted correctly with headers in the first row for seamless integration.

Features:

  • Sheet Name or GID Selection: Fetch data from specific sheets by name or GID (since v1.1.0 and v1.3.0 respectively).
  • Formatted Dates: While you can opt to retrieve dates in their displayed format within the spreadsheet with useFormattedDate (since v1.4.0), it is recommended to use the useFormat option available since v1.5.0 for more precise control and accuracy. The useFormat option ensures that both numeric and date values are returned in their formatted string representations as they appear in your Google Sheets, providing a more accurate and consistent result.
  • Custom Formatting: Leverage useFormat to get numeric and date values as formatted in Google Sheets (since v1.5.0).
  • Browser and Node.js Support: Utilize in various environments though note it requires Fetch API compatibility.
  • API Access: No API key required for the SDK; access data through the provided free API for public sheets.

Installation

yarn add public-google-sheets-parser
# OR
npm i public-google-sheets-parser

Usage

Node.js:

const PublicGoogleSheetsParser = require('public-google-sheets-parser')
const spreadsheetId = 'your_spreadsheet_id_here'
const parser = new PublicGoogleSheetsParser(spreadsheetId)

parser.parse().then(console.log)

Browser:

<script src="https://cdn.jsdelivr.net/npm/public-google-sheets-parser@latest"></script>
<script>
  const parser = new PublicGoogleSheetsParser('your_spreadsheet_id_here')
  parser.parse().then(data => console.log(data))
</script>

Vue v2:

<template>
  <div>
    <ul v-if="items.length">
      <li v-for="(item, index) in items" :key="index">{{ item }}</li>
    </ul>
  </div>
</template>

<script>
import PublicGoogleSheetsParser from 'public-google-sheets-parser'

export default {
  data() {
    return {
      items: [],
    }
  },
  mounted() {
    const parser = new PublicGoogleSheetsParser('your_spreadsheet_id_here')
    parser.parse().then(data => {
      this.items = data
    })
  },
}
</script>

React:

import React, { useState, useEffect } from 'react'
import PublicGoogleSheetsParser from 'public-google-sheets-parser'

const SpreadsheetData = () => {
  const [items, setItems] = useState([])

  useEffect(() => {
    const parser = new PublicGoogleSheetsParser('your_spreadsheet_id_here')
    parser.parse().then(data => {
      setItems(data)
    })
  }, [])

  return (
    <div>
      <ul>
        {items.map((item, index) => (
          <li key={index}>{JSON.stringify(item)}</li>
        ))}
      </ul>
    </div>
  )
}

export default SpreadsheetData

Options and Configurations

  • useFormattedDate: Although you can parse date values according to the spreadsheet's format using useFormattedDate, it is now recommended to use the useFormat option for more comprehensive and precise formatting control. The useFormat option not only affects dates but also applies to numeric values, ensuring consistency and accuracy across your data.

  • useFormat: Get data as formatted in the spreadsheet (applies to numbers and dates).

  • Specify sheet by name or GID to target specific data ranges.

Example with Options:

const options = { sheetName: 'Sheet4', useFormat: true }
const parser = new PublicGoogleSheetsParser('10WDbAPAY7Xl5DT36VuMheTPTTpqx9x0C5sDCnh4BGps', options)
parser.parse().then((data) => {
  // data will be like below:
  // [
  //   {
  //     date: '2024년 1월 1일 월요일 오전 12시 0분 0초',
  //     'with-format': '₩2,000.00',
  //     'without-format': '5678'
  //   },
  //   {
  //     date: '2024년 12월 1일 일요일 오전 12시 0분 0초',
  //     'with-format': '₩2,000.00',
  //     'without-format': '1234'
  //   }
  // ]
})

parser.setOption({ useFormat: false })
parser.parse().then((data2) => {
  // data2 will be like below:
  // [
  //   {
  //     date: 'Date(2024,0,1,0,0,0)',
  //     'with-format': 2000,
  //     'without-format': 5678
  //   },
  //   {
  //     date: 'Date(2024,11,1,0,0,0)',
  //     'with-format': 2000,
  //     'without-format': 1234
  //   }
  // ]
})

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.5.4

9 days ago

1.5.3

30 days ago

1.5.2

1 month ago

1.5.1

1 month ago

1.5.0

1 month ago

1.4.0

2 months ago

1.3.4

2 months ago

1.3.3

2 months ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.19

3 years ago

1.0.20

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.9

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago