basecardhero/spreadsheet

A Google services wrapper library for creating Google Sheets.

v0.3.0 2019-03-13 03:11 UTC

This package is auto-updated.

Last update: 2024-04-16 18:22:23 UTC


README

Build Status codecov License composer.lock

This package was created for a project I am working on and does not fully support Google services (or the way you may want it to). Feel free to add functionality by creating a pull request. See contributing.

Installation

You can install the package via composer:

$ composer require basecardhero/spreadsheet

Usage

You will need to configure the Google Client. See gsuitedevs/php-samples for examples configuring a Google Client for php.

Examples

Create a Spreadsheet instance

require_once '/project/path/vendor/autoload.php';


$client = new \Google_Client(); // Make sure to configure your Google client.
$sheetService = new \Google_Service_Sheets($client);
$spreadsheet = new \BaseCardHero\Spreadsheet\Spreadsheet($sheetService);

Create a spreadsheet

The create() method will fetch a new spreadsheet from the rest service.

$spreadsheet->create()
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Retrieve a spreadsheet

The retrieve() method will fetch an existing spreadsheet from the rest service.

$spreadsheetId = '1b7c48b64ef1d5bf093632e7f8aa6529';

$spreadsheet->retrieve($spreadsheetId)
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Set the title

$spreadsheet->create()
    ->setTitle('My Spreadsheet Title')
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Set column data

$columns = [
    [
        'range' => 'A1:A',
        'values' => [0, 1, 2, 3]
    ],
    [
        'range' => 'B1:B',
        'values' => ['a', 'b', 'c', 'd']
    ],
];

$spreadsheet->create()
    ->setColumns($columns)
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Clearing data on a spreadsheet

$spreadsheet->create()
    ->clearRanges(['A1:A', 'B1:B'])
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Copying a sheet from another spreadsheet

$otherSpreadsheetId = '635d0d664ff92db666a9be5ed84f231c';
$otherSheetId = 0;

$spreadsheet->create()
    ->copySheetFrom($otherSpreadsheetId, $otherSheetId)
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Delete a sheet within the spreadsheet

$sheetId = 0;

$spreadsheet->create()
    ->deleteSheet($sheetId)
    ->getSpreadsheet(); // \Google_Service_Sheets_Spreadsheet

Testing

$ composer all

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ryan@basecardhero.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.