optiwariindia / gsheet
A library to connect google sheet from web applications.
1.0.0
2021-07-08 20:56 UTC
Requires
- google/apiclient: ^2.10
This package is auto-updated.
Last update: 2025-06-09 05:34:46 UTC
README
Install
composer require optiwariindia/gsheet
Getting Started
Create Credentials at google cloud
- Open [Google Cloud Console]: https://console.cloud.google.com/
- Create a new project
- Navigate to API And Services > Credentials
- Click on "Create Credentials" link
- Select Credential type "Service Account"
- Fill the form and Grant the access
- Navigate to IAM & Admin > Service Accounts
- Click on Action link in front of service account just created.
- Select manage keys
- Now click on add key button and select key type "JSON"
- Save the file as credentials.json in the project root directory
Grant access to sheet
- Open "credentials.json" file you have downloaded from google.
- Find key named "Client_email" and copy the email besides it.
- Go to sheet you want to access
- Share that sheet with "Client_email" which you have just coppied.
Getting Google Sheet ID
- Check the url of your sheet https://docs.google.com/spreadsheets/d/_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_/edit#gid=0
- Copy the part after `https://docs.google.com/spreadsheets/d/" till next "/"
- Use this part as sheet id in the code.
Initializing Sheet
use optiwariindia\gsheet
gsheet::init("credentials.json",{SHEET_ID})
Add Data into new row
gsheet::addData("{Sheet Name}!{First Column Name}{Row Number}:{Last Column Name}",{Data to be inserted})
Search in specific column
gsheet::find("{Sheet Name}!{First Column Name}{Row Number}:{Last Column Name}",{keyword},{column number}})
Update Data in specific row
gsheet::updateData("{Sheet Name}!{First Column Name}{Row Number(to be updated)}:{Column Name}",{Data to be updated})
Delete Data from a row
gsheet::deleteData("{Sheet name}!{First Column Name}{Row Number}:{Last Column Number}{Row Number}")