PHP code example of mitni / laravel-google-spreadsheet

1. Go to this page and download the library: Download mitni/laravel-google-spreadsheet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mitni / laravel-google-spreadsheet example snippets


use Mitni\Google\GoogleSpreadsheet;

$client = GoogleSpreadsheet::getClient("the/path/to/credential.json");
// Get the file by file ID
$file = $client->file("XXXxxxXXXXxxxXXXX");
// Get the sheet by title
$sheet = $file->sheet("Sheet1");
// Flush all rows in the sheet
var_dump($sheet->items);

// Array
$items = $sheet->select(array("id" => "1"));
// Closure
$items = $sheet->select(function($row){
	return (int) $row["age"] < 30;
});

$sheet->insert(array(
	"name" => "John",
	"age" => 23,
	"email" => "[email protected]"
));

$sheet->update(
	8, // row number
	"name", // field's name (or column number as Integer)
	"Tom"
);

$items = $sheet->fetch(true)->items;

$client->config(array(
	"cache" => true,
	"cache_dir" => "cache",
	"cache_expires" => 3600
));