Spreadsheet

Worksheet management

Programmatically changes are available thought the following operations.


Create a new worksheet

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

use jexcel\Jexcel;

// Create the Jexcel Api with the Api Key
$client = new Jexcel('ZzAsMzQ0YWI1MmMzZjQwZjQ4MmQ6YWM2Njg3MzgwZWVmNDVkYzExZjJlN1==');

// Options for the new worksheet
$options = [
    'minDimensions' => [10, 10];
];

// Create the jexcel instance
$spreadsheet = $client->getSpreadsheet('946f23e8-ecd5-459c-b377-cc0c93200457');

// Create a new worksheet
$data = $spreadsheet->createWorksheet($options);

// Return the position of the new worksheet
print_r($data);

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

Rename worksheet

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

use jexcel\Jexcel;

// Create the jexcel instance
$client = new Jexcel('ZzAsMzQ0YWI1MmMzZjQwZjQ4MmQ6YWM2Njg3MzgwZWVmNDVkYzExZjJlN1==');

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet('946f23e8-ecd5-459c-b377-cc0c93200457');

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

// Result
print_r($data);

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

Delete worksheet

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

use jexcel\Jexcel;

// Create the jexcel instance
$client = new Jexcel('ZzAsMzQ0YWI1MmMzZjQwZjQ4MmQ6YWM2Njg3MzgwZWVmNDVkYzExZjJlN1==');

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet('946f23e8-ecd5-459c-b377-cc0c93200457');

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

// Result
print_r($data);

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

Update worksheet position

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

use jexcel\Jexcel;

// Create the jexcel instance
$client = new Jexcel('ZzAsMzQ0YWI1MmMzZjQwZjQ4MmQ6YWM2Njg3MzgwZWVmNDVkYzExZjJlN1==');

// Get the spreadsheet instance
$spreadsheet = $client->getSpreadsheet('946f23e8-ecd5-459c-b377-cc0c93200457');

// 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" }