1. Go to this page and download the library: Download lekoala/baresheet 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/ */
lekoala / baresheet example snippets
use LeKoala\Baresheet\Baresheet;
use LeKoala\Baresheet\Options;
// Read — format is auto-detected from the extension
$rows = Baresheet::read('data.xlsx', new Options(assoc: true));
foreach ($rows as $row) {
echo $row['email'];
}
// Write — format from extension
Baresheet::write($data, 'output.xlsx');
$rows = Baresheet::read('data.csv'); // Generator of rows
$rows = Baresheet::read('data.xlsx', new Options(assoc: true));
$rows = Baresheet::readString($contents, 'csv'); // from string content
Baresheet::write($data, 'output.ods'); // to file
$string = Baresheet::writeString($data, 'csv'); // to string
$stream = Baresheet::writeStream($data, 'xlsx'); // to resource
Baresheet::output($data, 'report.xlsx'); // to browser download
use LeKoala\Baresheet\Options;
use LeKoala\Baresheet\CsvReader;
use LeKoala\Baresheet\CsvWriter;
use LeKoala\Baresheet\XlsxWriter;
// CSV — manual pattern
$reader = new CsvReader();
$reader->assoc = true;
$rows = $reader->readFile('data.csv');
// XLSX — Options pattern
$writer = new XlsxWriter(new Options(
meta: ['creator' => 'My App'],
));
$writer->writeFile($data, 'report.xlsx');
$opts = new Options(
assoc: true,
separator: 'auto',
meta: ['creator' => 'My App'],
);
$opts->applyTo($reader); // full IDE autocomplete, reconfigures an existing instance
use LeKoala\Baresheet\Options;
use LeKoala\Baresheet\XlsxWriter;
$writer = new XlsxWriter(new Options(
boldHeaders: true,
autoWidth: true,
columnFormats: [
'A' => '@', // force text: keeps +972… and leading zeros
'C' => '0.00', // two-decimal number
],
columnWidths: ['A' => 20],
));
use LeKoala\Baresheet\Baresheet;
use LeKoala\Baresheet\Options;
use LeKoala\Baresheet\Exception\MissingColumnException;
use LeKoala\Baresheet\Exception\BaresheetException;
try {
$rows = iterator_to_array(Baresheet::read('products.csv', new Options(
use LeKoala\Baresheet\Value\TimeValue;
use LeKoala\Baresheet\Value\DurationValue;
$writer->writeFile([
[
'opening_time' => new TimeValue(9, 30),
'elapsed' => new DurationValue(hours: 36, minutes: 30, seconds: 15),
],
], 'report.xlsx');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.