Download the PHP package asimlqt/php-google-spreadsheet-client without Composer
On this page you can find all versions of the php package asimlqt/php-google-spreadsheet-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Short Description Google Spreadsheet PHP Client
All versions of php-google-spreadsheet-client with dependencies
Informations about the package php-google-spreadsheet-client
This library is no longer maintained. Please use the official Google PHP Client
- Retrieving a list of spreadsheets
- Retrieving a public spreadsheet
- Retrieving a list of worksheets
- Adding a worksheet
- Adding headers to a new worksheet
- Deleting a worksheet
- List feed
- Retrieving a list feed
- Adding a list row
- Updating a list row
- Cell feed
- Retrieving a cell feed
- Updating a cell
- Batch request
This library provides a simple interface to the Google Spreadsheet API v3.
There are a couple of important things to note.
- This library requires a valid OAuth access token to work but does not provide any means of generating one. The Google APIs Client Library for PHP has all the functionality required for generating and refreshing tokens so it would have been a waste of time duplicating the official Google library.
- You can not create spreadsheets using this library, as creating spreadsheets is not part of the Google Spreadsheet API, rather it's part of the Google Drive API. See the official Google APIs Client Library for PHP.
I strongly recommend you read through the official Google Spreadsheet API documentation to get a grasp of the concepts.
Using Composer is the recommended way to install it.
1 - Add "asimlqt/php-google-spreadsheet-client" as a dependency in your project's composer.json file.
2 - Download and install Composer.
3 - Install your dependencies.
4 - Require Composer's autoloader.
The first thing you will need to do is initialize the service request factory:
Note: For Windows users, you can disable the ssl verification by '$serviceRequest->setSslVerifyPeer(false)'
Retrieving a list of spreadsheets
Once you have a SpreadsheetFeed you can iterate over the spreadsheets using a foreach loop by calling the 'getEntries()' method or you can retrieve a single spreadsheet by it's title.
Note: The 'getByTitle' method will return the first spreadsheet found with that title if you have more than one spreadsheet with the same name.
Retrieving a public spreadsheet
A public spreadsheet is one that has been "published to the web". This does not require authentication. e.g.
The spreadsheet id can be copied from the url of the actual spreadsheet in Google Drive.
Retrieving a list of worksheets
You can retrieve a list of worksheets from a spreadsheet by calling the getWorksheets() method.
You can loop over each worksheet using 'getEntries()' or retrieve a single worksheet by it's title.
Adding a worksheet
To create a new worksheet simply use the 'addWorksheet()' method. This takes 3 arguments:
- Worksheet name
- Number of rows
- Number of columns
Adding headers to a new worksheet
The Google Spreadsheet API does not allow you to update a list row if headers are not already assigned. So, when you create a new worksheet, before you can add data to a worksheet using the 'Adding/Updating a list row' methods above, you need to add headers.
To add headers to a worksheet, use the following:
The only required parameter is the worksheet name, The row and column count are optional. The default value for rows is 100 and columns is 10.
Deleting a worksheet
It's also possible to delete a worksheet.
List feeds work at the row level. Each entry will contain the data for a specific row.
Note: You can not use formulas with the list feed. If you want to use formulas then you must use the cell feed (described below).
Retrieving a list feed
Once you have a list feed you can loop over each entry.
The getValues() method returns an associative array where the keys are the column names and the values are the cell content.
Note: The Google api converts the column headers to lower case so the column headings might not appear to be the same as what you see in Google Drive using your browser.
Note: If there is data for a particular row which does not have a column header then Google randomly generates a header and as far as I know it always begins with an underscore. Bear in mind that this is not generated by this library.
You can also sort and filter the data so you only retrieve what is required, this is expecially useful for large worksheets.
To find out all the available options visit https://developers.google.com/google-apps/spreadsheets/#sorting_rows.
Adding a list row
When adding or updating a row the column headers need to match exactly what was returned by the Google API, not what you see in Google Drive.
Updating a list row
Cell feed deals with individual cells. A cell feed is a collection of cells (of type CellEntry)
Retrieving a cell feed
Updating a cell
You can retrieve a single cell from the cell feed if you know the row and column numbers for that specific cell.
You can then update the cell value using the 'update' method. The value can be a primitive value or a formula e.g.
Updating multiple cells with a batch request
When attempting to insert data into multiple cells then consider using the batch request functionality to improve performance.
To use the batch request functionality you need access to a cell feed first. You can not use batch requests with list feeds.