google-sheet-apis
v0.0.3
Published
![npm](https://img.shields.io/npm/v/google-sheet-apis) ![npm](https://img.shields.io/npm/dw/google-sheet-apis) ![npm bundle size](https://img.shields.io/bundlephobia/min/google-sheet-apis)
Downloads
13
Maintainers
Readme
google-sheet-apis
How to use it
1. Install the package
npm
npm install google-sheet-apis
yarn
yarn add google-sheet-apis
2. Set up to access Google Sheet API
2.1 Create a new project in Google Console
Go to Google Console >> Select a project >> NEW PROJECT >> Type your project's name >> CREATE
2.2 Enable Google Sheets API
Select your project >> Search: Google Sheet API >> ENABLE
2.3 Create Service Accounts Credentials
Credentials >> + CREATE CREDENTIALS >> Service account >> Type your service'name >> CREATE AND CONTINUE >> CONTINUE >> DONE
2.4 Add JSON keys
Click on the email in Service Accounts >> KEYS >> ADD KEY >> Create new key >> JSON >> CREATE >> The key will be downloaded in your machine
3. Prepare a Google Sheet
Copy the email in Service Accounts >> Create a new Google Sheet >> Type your sheet name >> Share with the copied email >> Editor >> Done
Then, add some dummy data to test
4. Example to use the package
Example
const PRIVATE_KEY = 'your_private_key_in_the_json_file';
const CLIENT_EMAIL = 'your_client_email_in_the_json_file';
const { GoogleSheetApis } = require('google-sheet-apis');
const googleSheetApis = new GoogleSheetApis({
private_key: PRIVATE_KEY,
client_email: CLIENT_EMAIL,
});
const SPREADSHEET_ID = 'get_spreadsheet_id_in_the_sheet_URL';
// example https://docs.google.com/spreadsheets/d/1gJitO5lxYo499VYf_SyTob2Cg_iLsMwQVLDnPjBDbao/edit#gid=0
// spreadsheet id: 1gJitO5lxYo499VYf_SyTob2Cg_iLsMwQVLDnPjBDbao
const TAB_NAME = 'your_tab_name';
const START_COLUMN = 'A';
const END_COLUMN = 'F';
const getData = async () => {
const data = await googleSheetApis.getData({
spreadsheetId: SPREADSHEET_ID,
tabName: TAB_NAME,
startColumn: START_COLUMN,
endColumn: END_COLUMN,
});
console.log(data);
};
getData();