Download the PHP package reandimo/google-sheets-helper without Composer
On this page you can find all versions of the php package reandimo/google-sheets-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download reandimo/google-sheets-helper
More information about reandimo/google-sheets-helper
Files in reandimo/google-sheets-helper
Package google-sheets-helper
Short Description A bunch of functions to work easily with Google Sheets API
License MIT
Homepage https://github.com/reandimo/google-sheets-helper
Informations about the package google-sheets-helper
PHP Google Spreadsheets API Helper
Google Spreadsheets API Helper - A bunch of functions to work easily with Google Sheets API
This library is a helper that encapsulate Google APIs Client Library for PHP (Documentation) for simple usage.
Outline
- Requirements
- Installation
- Credentials
- Usage
- Create Instance
- Set sheets props
- Get Values
- Get values from range
- Append Data
- Append a single row
- Append a range
- Update Data
- Update single cell
- Update a range
- Worksheets
- Duplicate Worksheet
- Change background color of a range
- Misc
- Calculate column index by the letters
- License
- Question? Issues?
- Who's Behind
Requirements
This library requires the following:
- Dependent on Google Client API
- PHP 5.4 or greater with the command-line interface (CLI) and
- PHP extension JSON installed
- A Google Cloud Platform project with the API enabled. To create a project and enable an API, refer to Create a project and enable the API
Installation
Run Composer in your project:
composer require reandimo/google-sheets-helper
Then you could call it after Composer is loaded depending on your PHP framework:
Also, you can use putenv() to set credentials.json and token.json like this:
Now when you create a new instance, the class automatically detects the paths. This is the recommended way to do it.
Credentials
Google API Client needs to validate with 2 files credentials.json and token.json, the last one can be generated with a script included in the package called firstauth. You can use it to generate this file for the first time only to grant access to the API.
Execute in your project's root folder with php ./vendor/reandimo/google-sheets-helper/firstauth
and follow the steps.
This is a 3 step script based on the quickstart.php mentioned in google's documentation (https://developers.google.com/sheets/api/quickstart/php).
Usage
Create Instance
Set sheet props
You can have multiple sheet instances just invoke the Helper as many times you want:
Get Values
Get values from range
Append Data
Append a single row
The function will return a number of rows updated as int. So you can check if it's done like this:
Append a range
Update Data
Update single cell
Update a range
Worksheets
Duplicate Worksheet
Change background color of a range
Misc
Calculate column index by the letters
If for some reason you need to calculate the column positions of a column by its letters, this is the way:
Tips
Some things aren't very clear in Google's documentation without diggin a lot so i'll be leaving tips here:
-
To leave blank a cell when you do an insert or update, you have to use this const: .
Example:
License
This Package is open source and released under MIT license. See the LICENSE file for more info.
Question? Issues?
Feel free to open issues for suggestions, questions, and issues.
Who's Behind
Renan Diaz, i'm dealing with PHP since 2017 & Google's API since 2019. Feel free to write me to my email (Please don't send any multi-level crap).