Package Data | |
---|---|
Maintainer Username: | revolution |
Maintainer Contact: | kawaxbiz@gmail.com (kawax) |
Package Create Date: | 2016-06-26 |
Package Last Update: | 2024-11-21 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-19 03:01:49 |
Package Statistics | |
---|---|
Total Downloads: | 2,064,387 |
Monthly Downloads: | 71,558 |
Daily Downloads: | 3,020 |
Total Stars: | 414 |
Total Watchers: | 8 |
Total Forks: | 68 |
Total Open Issues: | 9 |
This package focused on read from Google Sheets
composer require revolution/laravel-google-sheets
This package depends on https://github.com/pulkitjalan/google-apiclient
Run php artisan vendor:publish --provider="PulkitJalan\Google\GoogleServiceProvider" --tag="config"
to publish the google config file
// config/google.php
// OAuth
'client_id' => env('GOOGLE_CLIENT_ID', ''),
'client_secret' => env('GOOGLE_CLIENT_SECRET', ''),
'redirect_uri' => env('GOOGLE_REDIRECT', ''),
'scopes' => [\Google_Service_Sheets::DRIVE, \Google_Service_Sheets::SPREADSHEETS],
'access_type' => 'online',
'approval_prompt' => 'auto',
'prompt' => 'consent', //"none", "consent", "select_account" default:none
// or Service Account
'file' => storage_path('credentials.json'),
'enable' => env('GOOGLE_SERVICE_ENABLED', true),
Get API Credentials from https://developers.google.com/console
Enable Google Sheets API
, Google Drive API
.
Configure .env as needed
GOOGLE_APPLICATION_NAME=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=
GOOGLE_DEVELOPER_KEY=
GOOGLE_SERVICE_ENABLED=
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=
https://github.com/kawax/google-sheets-project
|id|name|mail| |---|---|---| |1|name1|mail1| |2|name2|mail2|
https://docs.google.com/spreadsheets/d/{spreadsheetID}/...
use Sheets;
$user = $request->user();
$token = [
'access_token' => $user->access_token,
'refresh_token' => $user->refresh_token,
'expires_in' => $user->expires_in,
'created' => $user->updated_at->getTimestamp(),
];
// all() returns array
$values = Sheets::setAccessToken($token)->spreadsheet('spreadsheetId')->sheet('Sheet 1')->all();
[
['id', 'name', 'mail'],
['1', 'name1', 'mail1'],
['2', 'name1', 'mail2']
]
// get() returns Laravel Collection
$rows = Sheets::sheet('Sheet 1')->get();
$header = $rows->pull(0);
$values = Sheets::collection($header, $rows);
$values->toArray()
[
['id' => '1', 'name' => 'name1', 'mail' => 'mail1'],
['id' => '2', 'name' => 'name2', 'mail' => 'mail2']
]
view
@foreach($values as $value)
{{ data_get($value, 'name') }}
@endforeach
use Revolution\Google\Sheets\Sheets;
$client = \Google_Client();
$client->setScopes([Google_Service_Sheets::DRIVE, Google_Service_Sheets::SPREADSHEETS]);
// setup Google Client
// ...
$service = new \Google_Service_Sheets($client);
$sheets = new Sheets();
$sheets->setService($service);
$values = $sheets->spreadsheet('spreadsheetID')->sheet('Sheet 1')->all();
$values = Sheets::sheet('Sheet 1')->range('A1:B2')->all();
[
['id', 'name'],
['1', 'name1'],
]
Sheets::sheet('Sheet 1')->range('A4')->update([['3', 'name3', 'mail3']]);
$values = Sheets::range('')->all();
[
['id', 'name', 'mail'],
['1', 'name1', 'mail1'],
['2', 'name1', 'mail2'],
['3', 'name3', 'mail3']
]
Sheets::sheet('Sheet 1')->range('')->append([['3', 'name3', 'mail3']]);
$values = Sheets::range('')->all();
[
['id', 'name', 'mail'],
['1', 'name1', 'mail1'],
['2', 'name1', 'mail2'],
['3', 'name3', 'mail3']
]
$values = Sheets::sheet('Sheet 1')->majorDimension('DIMENSION_UNSPECIFIED')
->valueRenderOption('FORMATTED_VALUE')
->dateTimeRenderOption('SERIAL_NUMBER')
->all();
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get#query-parameters
$sheets->spreadsheets->...
$sheets->spreadsheets_sheets->...
$sheets->spreadsheets_values->...
Sheets::getService()->spreadsheets->...
see https://github.com/google/google-api-php-client-services/blob/master/src/Google/Service/Sheets.php
MIT
Copyright kawax