PHP code example of yakub / yxel

1. Go to this page and download the library: Download yakub/yxel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yakub / yxel example snippets


\Yakub\Yxel\Main::setCreatingDir('/my/path/to/creating');

$read = \Yakub\Yxel\Main::read('path/to/file.csv');

$read->getRows(function ($data, $row) {
	echo $row.' -> '.json_encode($data).'<br >';
});

$write = \Yakub\Yxel\Main::write('yxel_test', \Yakub\Yxel\Main::CSV);

$write->addRow(['A1', 'B1', '']);
$write->addRow(['A2', '', 'C2']);

$write->close();

// Return full path to file
$patToFile = $write->getFilePath();

$read = \Yakub\Yxel\Main::read('path/to/file.xlsx');

$read->getRows(function ($data, $row) {
	echo $row.' -> '.json_encode($data).'<br >';
});

$write = \Yakub\Yxel\Main::write('yxel_test', \Yakub\Yxel\Main::XLSX);

$write->addRow(['A1', 'B1', '']);
$write->addRow(['A2', '', 'C2']);

$write->close();

// Return full path to file
$patToFile = $write->getFilePath();

$write = \Yakub\Yxel\Main::write('yxel_test', \Yakub\Yxel\Main::CSV);

$write->addRow(['A1', 'B1', '']);
$write->addRow(['A2', '', 'C2']);

// Instead of close use save. This function only save new data but file is still able to get new rows. Also this help clean memory.
// After save script can end and data will not be lost
$write->save();

// Name of file must be same
$write = \Yakub\Yxel\Main::write('yxel_test', \Yakub\Yxel\Main::CSV);

// Add new row to previous in this file
$write->addRow(['', 'B3', 'C3']);

// After close can't open this file again. If is used same name then file will be rewrited with new data
$write->close();

$write = \Yakub\Yxel\Main::write('yxel_test', \Yakub\Yxel\Main::CSV);

$write->addRow(['A1', 'B1', '']);
$write->addRow(['A2', '', 'C2']);

$write->settings('row_number', 3);
$write->save();

// ------- New process ------- //

$write = \Yakub\Yxel\Main::write('yxel_test', \Yakub\Yxel\Main::CSV);
$row = $write->settings('row_number');

$write->addRow(['', 'B'.$row, 'C'.$row]);

$write->close();