PHP code example of rationalboss / gsheet-manager

1. Go to this page and download the library: Download rationalboss/gsheet-manager 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/ */

    

rationalboss / gsheet-manager example snippets


$client = Google_Spreadsheet::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"
);

$sheet->update(
	array(8,16,24), // row numbers
	"name",
	"Tom"
);

$sheet->update(
	array(
		"name" => "Tom" // condition to select
	),
	"email",
	"[email protected]"
);

$sheet->update(
	function($row){
		return (int) $row["age"] > 80; // condition to select as closure
	},
	"active",
	"false"
);

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

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