Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stopsopa/google-spreadsheets-api-extension
My own approach to manipulating data in Google Spreadsheets
https://github.com/stopsopa/google-spreadsheets-api-extension
Last synced: 22 days ago
JSON representation
My own approach to manipulating data in Google Spreadsheets
- Host: GitHub
- URL: https://github.com/stopsopa/google-spreadsheets-api-extension
- Owner: stopsopa
- License: mit
- Created: 2016-04-01T07:35:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-09-02T00:19:22.000Z (about 1 year ago)
- Last Synced: 2024-10-05T00:09:01.746Z (about 1 month ago)
- Language: PHP
- Size: 48.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/stopsopa/google-spreadsheets-api-extension.svg?branch=master)](https://travis-ci.org/stopsopa/google-spreadsheets-api-extension)
[![Latest Stable Version](https://poser.pugx.org/stopsopa/google-spreadsheets-api-extension/v/stable)](https://packagist.org/packages/stopsopa/google-spreadsheets-api-extension)
[![Coverage Status](https://coveralls.io/repos/github/stopsopa/google-spreadsheets-api-extension/badge.svg?branch=master)](https://coveralls.io/github/stopsopa/google-spreadsheets-api-extension?branch=master)
[![License](https://poser.pugx.org/stopsopa/google-spreadsheets-api-extension/license)](https://packagist.org/packages/stopsopa/google-spreadsheets-api-extension)# DEPRECATED
Created in 2016 - quite old now and not maintained.# stopsopa/google-spreadsheets-api-extension
## Instalation
Follow packagist instructions: [Packagist](https://packagist.org/packages/stopsopa/google-spreadsheets-api-extension
)## Setup access to google spreadsheet documents
First You need to generate credentials in [Google API Console](https://console.developers.google.com) and setup **Service account keys** (read [more](https://support.google.com/cloud/answer/6158849?hl=en#serviceaccounts)). After that you recieve file '.p12' which is a private key and special e-mail address (eq: [email protected]) that you should use to give access to api to specific spreadsheets in google-drive.
## Setup this library
```
use Stopsopa\GoogleSpreadsheets\Services\GoogleSpreadsheets;$service = new GoogleSpreadsheets();
$service->setupByServiceAccountKey(
'pathtofile.p12',
'[email protected]'
);
```... and now you are ready to go.
# Api
Most of methods is pretty self-explanatory so normally you can explore them through IDE or just by exploring returned data structures (especially if you read [terminology](https://developers.google.com/google-apps/spreadsheets/#terminology_used_in_this_guide) used in Sheets API), they don't need to be explained here in details, but it is also good thing to list them here. It is also good idea to see [tests](https://github.com/stopsopa/google-spreadsheets-api-extension/blob/master/Tests/GoogleSpreadsheetsTest.php) starting from method **testFindWorksheets**.
## Methods of GoogleSpreadsheets class
Method with default parameters | Returned type | Additional description
------------------------------ | ------------- | ----------------------
$service->findSpreadsheets($rawResponse = false); | array |
$service->findWorksheets($key, $rawResponse = false); | array |
$service->getWorksheetMetadata($key, $wid); | array |
$service->updateWorksheetMetadata($key, $wid, $title = null, $rows = null, $cols = null); | array |
$service->findWorksheetData($key, $wid, $rawResponse = false, $filter = array()); | array |
$service->deleteWorksheet($key, $wid); | array |
$service->update($key, $wid, $data); | array | [doc](https://github.com/stopsopa/google-spreadsheets-api-extension#method-googlespreadsheets-update)
$service->findFirstFreeRowForData($key, $wid); | int (1 indexed) |
$service->getList($key, $wid); | [GoogleSpreadsheetsList](https://github.com/stopsopa/google-spreadsheets-api-extension/blob/master/Services/GoogleSpreadsheetsList.php) |## Methods of GoogleSpreadsheetsList class
Read more about [list based feed](https://developers.google.com/google-apps/spreadsheets/data#work_with_list-based_feeds).
Method with default parameters | Returned type | Additional description
------------------------------ | ------------- | -----------------------
$list->add($data); | array | [doc](https://github.com/stopsopa/google-spreadsheets-api-extension/blob/master/README.md#method-googlespreadsheetslist-add)
$list->update($row, $data); | array | $row is 1 indexed, $data format like above
$list->get($filters = null); | array | $filters format see [this](https://github.com/stopsopa/google-spreadsheets-api-extension#filter).
Usually use only min-row, max-row.## Commonly used parameters
### $rawResponse:
Many of this methods has special parameter **$rawResponse**, setting up this to true turns returned data structure to raw form, just like it's comes from google api. But in most cases it is better to leave this parameter as is and get more consist and better to iterate through data structure at the output of this methods.
## $key
You can find the key in the spreadsheet URL (bolded in below example).
https://docs.google.com/spreadsheets/d/**1IAP4HOacD4Az6q_PFfxxxxxxxxxxxxxxxx9KBX-IMO25s**/edit?usp=sharing
## $wid
This is unique identifier for each worksheet in spreadsheet, You can get these ids by using method **findWorksheets**.
## $filter
This parameter is used to fetch specific rows or columns ranges from worksheet, eq:
$result = $service->findWorksheetData($key, $wid, false, array(
'max-col' => 4,
'max-row' => 3
));
For more informations see in google api [Fetch specific rows or columns](https://developers.google.com/google-apps/spreadsheets/data#fetch_specific_rows_or_columns).## Other details
### Method GoogleSpreadsheets->update()
$service->update($key, $wid, array(
'A1' => "Name",
'B1' => "Surname",
'C1' => "Age",
'D1' => "Weight",
'E1' => "Height",
'A2' => "Something else... ",
'R2C5' => "And again...",
'R3C2' => '' // empty string to delete value from cell
));
Using this method you can use two types of [positioning notations](https://developers.google.com/google-apps/spreadsheets/data#work_with_cell-based_feeds). Using method *update* you can set/update/delete data in many cells by one [batch request](https://developers.google.com/google-apps/spreadsheets/data#update_multiple_cells_with_a_batch_request).To convert in both ways these two types of formats use [this](https://github.com/stopsopa/google-spreadsheets-api-extension/blob/master/Utils/CellConverter.php) lib.
### Method GoogleSpreadsheetsList->add()
$list->add(array(
'Name' => 'John',
'Surname' => 'Smith',
'Age' => '35'
));
To read more about basic assumptions that describes working with list based feeds go [here](https://developers.google.com/google-apps/spreadsheets/data#work_with_list-based_feeds).
## License
The MIT License (MIT)
Copyright (c) 2016 Szymon Działowski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.