Jexcel Api

Insert rows

Add a new row at the end of the spreadsheet

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

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

// Result
print_r($spreadsheet->getRows()->insert($data));

// { "numOfRows": 1, "rowNumber": 2, "insertBefore": "false" }

Adding a new row after line 5

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

$data = [
    ['Apple', '$3.442', 'USA'],
    ['Airtables', '$1.112', 'USA'],
    ['Handsontable', '$124', 'USA'],
];

// Result
print_r($spreadsheet->getRow(5)->insert($data, false));

// { "rowNumber": "5", "numOfRows": "3", "insertBefore": "0", "data": [{"row":"5","data":["Apple","$3.442","USA"]},{"row":"6","data":["Airtables","$1.112","USA"]},{"row":"7","data":["Handsontable","$124","USA"]}] }


Row position

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

// Result
print_r($spreadsheet->getRow(0)->moveTo(1));

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

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

// Result
print_r($spreadsheet->getRow(1)->moveTo(0));

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

Delete rows

Delete the first row

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

// Result
print_r($spreadsheet->getRow(0)->delete());

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

Delete rows 4,5,6

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

// Result
print_r($spreadsheet->getRow(3)->delete(3));

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

Row height

Define the height of a first row to 30px

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

// Result - 30 pixels
print_r($spreadsheet->getRow(0)->setHeight(30));

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

Define the height of multiple rows

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

// Result - 35 pixels
print_r($spreadsheet->getRows([2, 3, 4])->setHeight(35));

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

Get the height of the first row

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

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

// [ {"height":30} ]

Get the height of multiple rows

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

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

// { "2": {"height": 35}, "3": {"height": 35}, "4": {"height": 35} }

Row data

Get the data from multiple rows

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

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

/*
[
    {"row":0,"data":["A1","B1",null,null,null,null,null,null,null,null]},
    {"row":2,"data":["A3","B3",null,null,null,null,null,null,null,null]}
]
*/

Get data from the first row

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

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

/*
[
    {"row":0,"data":["A1","B1",null,null,null,null,null,null,null,null]}
]
*/