Holy Sheet is a vanilla JS plugin for fetching data from Google Sheets simply from the Sheet link. You only provide your Sheet ID and it'll fetch data as JS Object or CSV format. NO API setup or anything is required.
Clone this repo and run the following commands.
First install npm packages
npm install
Then run
npm start
# output
> holy-sheet@1.0.0 start
> parcel index.html
Server running at http://localhost:1234
Built in 1.60s
Visit http://localhost:1234
to see the result. Your port may not be 1234
!
For testing you can use this demo sheet.
First you need to get the plugin file HolySheet.js
. Copy it to your JS
directory. You can create a directory called plugins/
in your JS directory
and put the HolySheet.js
in it.
In your index.js
file you want to instantiate the object as shown in example below:
import HolySheet from './js/plugins/HolySheet';
const config = {
sheetId: "1hxrpqGnVjs9efoq-eblYm8M3AHMDY9Q6vOihvHRxdZg",
sheetName: 'user-data',
sheetRange: 'A1:D20',
dataType: 'json'
};
const holySheet = new HolySheet(config);
holySheet.fetchData().then(data => renderData(data));
It takes an config object as an argument.
-
sheetId
is the ID that you get from your sheet URL for example:https://docs.google.com/spreadsheets/d/1hxrpqGnVjs9efoq-eblYm8M3AHMDY9Q6vOihvHRxdZg/edit#gid=1460352599
Your
sheetId
is inbetween/d/<sheetId>/edit#
. In above URL thesheetId
is:1hxrpqGnVjs9efoq-eblYm8M3AHMDY9Q6vOihvHRxdZg
-
sheetName
is the name of the sheet/tab. -
sheetRange
is the data range you want to fetch. For example from cellA1
untilD20
.Note: You must have a header and always start your range from A1 otherwise you'll not get the desired result!
-
dataType
specifies in what form data should be retrieved. You can either set it tojson
orcsv
. When yourdataType
is set tojson
thefetchData()
method will return a promise with JS object. If it is set tocsv
then it will return raw CSV data.