Worksheet management

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

Documentation

Methods

The following methods are available to interact with the spreadsheet headers programmatically.
MethodDescription
createWorksheet Create a new worksheet.
createWorksheet(
options?: Partial<Worksheet>
): Promise<{ worksheet: number; worksheetId: string }>

@param options - worksheet options.

POST /api/:guid/worksheets
renameWorksheet Rename the worksheet.
renameWorksheet(worksheet: number, newValue: string): Promise<void>
@param worksheet - worksheet position
@param newValue - new title

POST /api/:guid/worksheets/rename
moveWorksheet Move a worksheet position.
moveWorksheet(from: number, to: number): Promise<void>
@param from - worksheet position.
@param to - new position.

POST /api/:guid/worksheets/move
deleteWorksheet Delete a worksheet by its position.
deleteWorksheet(worksheetPosition: number): Promise<void>
@param worksheetPosition - worksheet position.

DELETE /api/:guid/worksheets/:worksheetPosition
setWorksheet Change the worksheet being used by the client api. It has no effect on the spreadsheet, it's just an internal method of the client api.
setWorksheet(worksheetIndex: number): void
@param worksheetIndex - worksheet position.


Examples

Create a new worksheet

The worksheet position and unique-id is returned.

NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create a new client
const client = new Client(token);

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Options for the new worksheet @See Jspreadsheet documentation for more options
const options = {
    minDimensions: [10, 10],
};

// Result
spreadsheet.createWorksheet().then((newWorksheet) => {
    console.log(newWorksheet);
});

// {
//     worksheet: 1,
//     worksheetId: "c216d2cd"
// }
<?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

How to rename a remote worksheet.

NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create a new client
const client = new Client(token);

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Rename the first worksheet
spreadsheet.renameWorksheet(0, "New title for the first worksheet").then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});
<?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" }

Update worksheet position

How to change the worksheet order on a remote spreadsheet.

NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create a new client
const client = new Client(token);

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Update the second worksheet to the third position
spreadsheet.moveWorksheet(1, 2).then(() => {
    // It worked correctly
})
.catch((err) => {
    console.log(err);
});
<?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" }

Delete worksheet

How to delete a remote worksheet.

NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create a new client
const client = new Client(token);

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Delete the first worksheet
spreadsheet.deleteWorksheet(0).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});
<?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" }

Set worksheet

How to change the worksheet being used.

NodeJS
PHP
import { Client } from '@jspreadsheet/client';

// Access token
const token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create a new client
const client = new Client(token);

// Get the spreadsheet instance
const spreadsheet = client.getSpreadsheet(guid);

// Get data from worksheet 0
spreadsheet.getData().then((result) => {
  console.log(result);
});

// Change the worksheet being used
spreadsheet.setWorksheet(1);

// Get data from worksheet 1
spreadsheet.getData().then((result) => {
  console.log(result);
});