Spreadsheet column operations

The following methods are available for column operations.

Documentation

Methods

The following methods are available to interact with the spreadsheet headers programmatically.
MethodDescription
insertColumn Add a new column.
insertColumn(options: {
data?: string[][];
properties?: Column[];
insertBefore?: boolean;
numOfColumns: number;
columnNumber?: number;
}): Promise<void>

@param options.data - new column data.
@param options.properties - new column properties.
@param options.insertBefore - insert before or after the reference column.
@param options.numOfColumns - number of columns to insert.
@param options.columnNumber - reference column for insert.

POST /api/:guid/columns
moveColumn Change the column position.
moveColumn(from: number, to: number): Promise<void>
@param from - column number.
@param to - to the position.

POST /api/:guid/columns/move
deleteColumn Delete one or multiple columns.
deleteColumn(columnNumber: number, numOfColumns?: number): Promise<void>
@param columnNumber - column number.
@param numOfColumns - number of columns. The default is 1.

POST /api/:guid/columns/delete
setWidth Define the width of one or multiple columns.
setWidth(column: number, width: number): Promise<void>
setWidth(column: number[], width: number | number[]): Promise<void>

@param column - column number(s).
@param width - new width.

POST /api/:guid/width
getWidth Get the with of one or multiple columns.
getWidth(
columns?: number | number[]
): Promise<{ [columnNumber: number]: number }>

@param columns - column number. If not informed, all columns will be returned.

GET /api/:guid/width


Examples

Insert columns

Add a new column in a specific position


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);

// Insert before flag
cosnt insertBefore = true;

// Column properties
const properties = [
    {
        title: "new A",
        type: "text",
    },
];

// Add a new column on the second position. Position start on zero
spreadsheet.insertColumn({
    columnNumber: 1,
    numOfColumns: 1,
    insertBefore,
    properties,
}).then(() => {
    // It worked correctly
}).catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Insert before flag
$insertBefore = true;

// Column properties
$properties = [['title' => 'new A', 'type' => 'text']];

// Add a new column on the second position. Position start on zero.
$result = $spreadsheet->getColumn(1)->insert($insertBefore, $properties);

// Result: { "success": 1, "message": "Updated" }

Add a new column at the end with data


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);

// Insert before flag
const insertBefore = false;

// Column properties
const properties = [
    {
        title: "new A",
        type: "text",
    },
];

// Add a new column at the end
spreadsheet.insertColumn({
    numOfColumns: 1,
    insertBefore,
    properties,
}).then(() => {
    // It worked correctly
}).catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Insert before flag
$insertBefore = false;

// Column properties
$properties = [['title' => 'new A', 'type' => 'text']];

// Add a new column on the second position. Position start on zero.
$result = $spreadsheet->getColumns()->insert($insertBefore, $properties);

// Result
print_r($result);


Column position

Change a column position


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);

// Move the first column to the second position
spreadsheet.moveColumn(0, 1).then(() => {
    // It worked correctly
}).catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Move the column zero to the second position
$result = $spreadsheet->getColumn(0)->moveTo(1);

// {"success":1, "message": "Updated"}


Delete columns

Delete the column from a specific position


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 first column
spreadsheet.deleteColumn(0).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Delete first column
$result = $spreadsheet->getColumn(0)->delete();

// Result
print_r($result);

Delete multiple columns


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 2 columns
spreadsheet.deleteColumn(0, 2).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Delete the first 2 columns
$result = $spreadsheet->getColumn(0)->delete(2);

// Result
print_r($result);


Column width

Define the width of a column


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);

// Set the position of the third column to 200px
spreadsheet.setWidth(2, 200).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Set the position of the third column to 200px
$result = $spreadsheet->getColumn(2)->setWidth(200);

// Result
print_r($result);

// {"success": 1, "message": "Updated"}

Define the width of multiple columns


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);

// Define the width of the forth and fifth columns to 250px
spreadsheet.setWidth([3, 4], 250).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something went wrong
    console.log(err);
});
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Define the width of the forth and fifth columns to 250px
$result = $spreadsheet->getColumns([3,4])->setWidth(250);

// Result
print_r($result);

Get the width from multiple columns


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 the width from multiple columns
spreadsheet.getWidth([3, 4]).then((widths) => {
    console.log(widths);
});

// {
//     "3": 250,
//     "4": 250,
// }
<?php
require 'vendor/autoload.php';

use jspreadsheet\Jspreadsheet;

// Access token
$token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz';

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

// Create the client instance
$client = new Jspreadsheet($token);

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

// Get the width from multiple columns
$result = $spreadsheet->getColumns([3, 4])->getWidth();

// Result
print_r($result);

// Array ( [3] => 250 [4] => 250 )



Create applications with spreadsheet-like controls