Products

Spreadsheet rows operations

The following methods are available for rows operations.

Documentation

Methods

The following methods are available to interact with the spreadsheet headers programmatically.
MethodDescription
getRow Get a row data.
getRow(
rowNumber: number | number[]
): Promise<{ row: number; data: string[] }[]>

@param rowNumber - row number

GET /api/:guid/rows/:rows
insertRow Insert a new row.
insertRow(options?: {
numOfRows?: number;
rowNumber?: number;
insertBefore?: boolean;
data?: (
| { data: { [key: string]: string } | string[] }
| { [key: string]: string }
| string[]
)[];
}): Promise<{
numOfRows: number;
rowNumber: number;
insertBefore: boolean;
data: {
row: number;
data: string[];
};
}>

@param numOfRows - number of rows that must be inserted. Default is 1.
@param rowNumber - reference row for insertion. Default is the last row.
@param insertBefore - insert before or after reference line. Default is false.
@param data - row instructions object. New row values.

POST /api/:guid/rows
moveRow Change the row position.
moveRow(from: number, to: number): Promise<void>
@param from - row number.
@param to - to the position.

POST /api/:guid/rows/move
deleteRow Delete rows.
deleteRow(rowNumber: number, numOfRows?: number): Promise<void>
@param rowNumber - row number.
@param numOfRows - number of rows. Default is 1.

POST /api/:guid/rows/delete
setHeight Update the row height.
setHeight(row: number, height: number): Promise<void>
setHeight(row: number[], height: number | number[]): Promise<void>

@param row - row number.
@param height - new height.

POST /api/:guid/height
getHeight Get the height of one or multiple rows.
getHeight(
rowNumber?: number | number[]
): Promise<{ [rowNumber: string]: number }>

@param rowNumber - row number. If omitted, returns the heights of all rows.

GET /api/:guid/height


Examples

Insert rows

Add a new row at the end of the 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);

const data = [['Apple', '$3.442', 'USA']];

// Insert data
spreadsheet.insertRow({ data }).then((result) => {
    console.log(result);
});

// {
//     numOfRows: 1,
//     rowNumber: 5,
//     insertBefore: 0,
//     data: [{
//         id: 5075,
//         row: 6,
//         data: [
//             "Apple",
//             "$3.442",
//             "USA",
//         ],
//     }],
// }
<?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);

$data = [['Apple', '$3.442', 'USA']];

// Insert data
$result = $spreadsheet->getRows()->insert($data);

// Result
print_r($result);

// {"success":1,"message":"Updated","data":{"numOfRows":1,"rowNumber":5,"insertBefore":0,"data":[{"id":5075,"row":6,"data":["Apple","$3.442","USA"]}]}}

Adding a new row after line 5


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

const data = [['1', '2', '3'], ['4', '5', '6']];

// Insert data
spreadsheet.insertRow({
    rowNumber: 5,
    insertBefore: false,
    data
}).then((result) => {
    console.log(result);
});

// {
//     numOfRows: 2,
//     rowNumber: 5,
//     insertBefore: 0,
//     data: [
//         { id: 5077, row: 6, data: ["1", "2", "3"]},
//         { id: 5078, row: 7, data: ["4", "5", "6"]}
//     ]
// }
<?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);

$data = [['1', '2', '3'],['4', '5', '6']];

// Insert data
$result = $spreadsheet->getRow(5)->insert($data, false);

// Result
print_r($result);

// {"success":1,"message":"Updated","data":{"numOfRows":2,"rowNumber":5,"insertBefore":0,"data":[{"id":5077,"row":6,"data":["1","2","3"]},{"id":5078,"row":7,"data":["4","5","6"]}]}}


Row position

Change the row position, from the first to the second 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);

spreadsheet.moveRow(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);

$result = $spreadsheet->getRow(0)->moveTo(1);

// Result
print_r($result);

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

Delete rows

Delete the first row


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 row
spreadsheet.deleteRow(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 the first row
$result = $spreadsheet->getRow(0)->delete();

// Result
print_r($result);

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

Delete rows 4,5,6


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 three rows from the forth column
spreadsheet.deleteRow(3, 3).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 three rows from the forth column
$result = $spreadsheet->getRow(3)->delete(3);

// Result
print_r($result);

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

Row height

Define the height of a first row to 30px


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 height
spreadsheet.setHeight(0, 30).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 three rows from the forth column
$result = $spreadsheet->getRow(0)->setHeight(30);

// Result
print_r($result);

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

Define the height of multiple rows


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 height
spreadsheet.setHeight([0, 1, 2], 50).then(() => {
    // It worked correctly
})
.catch((err) => {
    // Something weng 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 three rows from the forth column
$result = $spreadsheet->getRows([0,1,2])->setHeight(50);

// Result
print_r($result);

Get the height of the first row


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

// Result
spreadsheet.getHeight(0).then((heights) => {
    console.log(heights);
});

// {
//     "0": {
//         height: 30
//     }
// }
<?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);

// Result
$result = $spreadsheet->getRow(0)->getHeight();

// Result
print_r($result);

// [ {"height":30} ]

Get the height of multiple rows


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

// Result
spreadsheet.getHeight([2, 3, 4]).then((heights) => {
    console.log(heights);
});

// {
//     "1": { height: 50 },
//     "2": { height: 142 },
//     "3": { height: 175 },
// }
<?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);

// Result
$result = $spreadsheet->getRows([2,3,4]])->getHeight();

// Result
print_r($result);

// {"1":{"height":50},"2":{"height":142},"3":{"height":175}}

Row data

Get the data from multiple rows


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

// Result
spreadsheet.getRow([0, 1]).then((rows) => {
    console.log(rows);
});

// [
//     {
//         row: 0, data: ["b", "a", "", "1", "sdfg"]
//     },
//     {
//         row: 1, data: ["", "", "", "1", ""]
//     },
// ]
<?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);

// Result
$result = $spreadsheet->getRows([0, 1])->getData();

// Result
print_r($result);

// [{"row":0,"data":["b","a",null,"1","sdfg"]},{"row":1,"data":[null,null,null,"1",null]}]

Get data from the first row


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

// Result
spreadsheet.getRow(0).then((rows) => {
    console.log(rows);
});

// [
//     {
//         row: 0, data: ["b", "a", "", "1", "sdfg"]
//     },
// ]
<?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);

// Result
$result = $spreadsheet->getRow(0)->getData();

// Result
print_r($result);