Laravel Google SpreadSheet

Star Total Downloads Build Status Latest Stable Version

Google spreadsheet transforms to json and storing to file with laravel.

Installation

You can install the package via composer:

composer require yish/laravel-googlespreadsheet

If you need to set access type, you can publish config.

This package depends on pulkitjalan/google-apiclient, so you need publish pulkitjalan/google-apiclient config and setup.

    'service' =>  [
        'enabled' => true,
        'file' => 'your-service-account-json-file-path',
    ],

You need to check your service account and configs are all done.

  1. google console
  2. service account
  3. download credential.json
  4. enabled sheet api
  5. paste service account to sheet account permission

Requirement

Laravel 5.8 or 6.*

Usage

// $sheet_id = your google spreadsheet id.
// $range = you need column range, like 'Class Data!A2:E', if you use chinese, using double quote. "'首頁'!A2:E".
// $title = you want to set which one be a title key.
// $unset = you want to unset which columns. 
// $scope = Google_Service_Sheets::SPREADSHEETS_READONLY.
GoogleSpreadSheet::json($sheet_id, $range, $title = 0, $unset = [], $scope = null)
GoogleSpreadSheet::json($sheet_id, 'index!A2:E', 0, [1, 2]) // get the sheet and set 0 column to be title key, unset column 1 and column 2.
// You can chain the storeAs.
GoogleSpreadSheet::json($sheet_id, 'index!A2:E', 0, [1, 2])->storeAs($path, $disk = 'public')
// Or you can use feed.
GoogleSpreadSheet::feed($sheet_id, $sheet = 1, $format = 'json')