Spreadsheet

Worksheet management

Programmatically changes on the worksheet level are available through the following operations.


Create a new worksheet

The worksheet Position and worksheet of the new worksheet is returned.
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

// Spreadsheet Guid
$guid = '15eb1171-5a64-45bf-be96-f52b6125a045';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid);

// Options for the new worksheet @See Jspreadsheet documentation for more options
$options = [
'minDimensions' => [10, 10]
];

// Result
$result = $spreadsheet->createWorksheet($options);

print_r($result);

// {"success":1,"message":"Successfully created","worksheet":1,"worksheetId":"c216d2cd"}

Rename worksheet

<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
$guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid);

// Get the first worksheet and rename it.
$result = $spreadsheet->getWorksheet(0)->rename('New title for the first worksheet');

// { "success":1, "message":"Successfully updated" }

Delete worksheet

<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
$guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid);

// Get the spreadsheet instance, get the first worksheet and delete it.
$result = $spreadsheet->getWorksheet(0)->delete();

// Result
print_r($result);

// { "success":1, "message":"Successfully deleted" }

Update worksheet position

<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSxlMjE2MWI5YWNjYTg2MzM4MThmN2Y4NjY0YmQzYzBlOGExMmVkZjVk';

// Spreadsheet Guid
$guid = '79b45919-c751-4e2b-a49a-6c1286e2fc03';

// Create a new client
$client = new Jspreadsheet($token);

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet($guid);

// Get the spreadsheet instance, get the second worksheet and update to the third position
$data = $spreadsheet->getWorksheet(1)->move(2); // Position starts on zero

// Result
print_r($data);

// { "success":1, "message":"Successfully updated" }