在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kawax/laravel-google-sheets开源软件地址(OpenSource Url):https://github.com/kawax/laravel-google-sheets开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Google Sheets API v4 for LaravelRequirements
Versioning
InstallationComposer
Laravel
DemoAnother Google API Series.
Usage
https://docs.google.com/spreadsheets/d/{spreadsheetID}/... Basic Laravel Usageuse 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']
// ] Basic Non-Laravel Usageuse Google\Client;
use Revolution\Google\Sheets\Sheets;
$client = new 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(); Get a sheet's values with the header as the key// 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']
// ] Blade @foreach($values as $value)
{{ data_get($value, 'name') }}
@endforeach Using A1 Notation$values = Sheets::sheet('Sheet 1')->range('A1:B2')->all();
// [
// ['id', 'name'],
// ['1', 'name1'],
// ] Updating a specific rangeSheets::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']
// ] Append a set of values to a sheet// When we don't provide a specific range, the sheet becomes the default range
Sheets::sheet('Sheet 1')->append([['3', 'name3', 'mail3']]);
$values = Sheets::all();
// [
// ['id', 'name', 'mail'],
// ['1', 'name1', 'mail1'],
// ['2', 'name1', 'mail2'],
// ['3', 'name3', 'mail3']
// ] Append a set of values with keys// When providing an associative array, values get matched up to the headers in the provided sheet
Sheets::sheet('Sheet 1')->append([['name' => 'name4', 'mail' => 'mail4', 'id' => 4]]);
$values = Sheets::all();
// [
// ['id', 'name', 'mail'],
// ['1', 'name1', 'mail1'],
// ['2', 'name1', 'mail2'],
// ['3', 'name3', 'mail3'],
// ['4', 'name4', 'mail4'],
// ] Add a new sheetSheets::spreadsheetByTitle($title)->addSheet('New Sheet Title'); Deleting a sheetSheets::spreadsheetByTitle($title)->deleteSheet('Old Sheet Title'); Specifying query parameters$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 Use original Google_Service_Sheets$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 LICENSEMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论