PhpSpreadsheetLite is a lightweight library designed to simplify creating and reading spreadsheets in CSV or XLSX formats using PhpSpreadsheet. It provides an intuitive API for quick and efficient spreadsheet operations.
- PHP 8.1 or higher
- PhpSpreadsheet library (automatically installed via Composer)
Install the package via Composer. This will also install phpoffice/phpspreadsheet automatically:
composer require ceytek-labs/php-spreadsheet-lite
Here’s an example of how to use PhpSpreadsheetLite:
use CeytekLabs\PhpSpreadsheetLite\PhpSpreadsheetLite;
use CeytekLabs\PhpSpreadsheetLite\SpreadsheetFormat;
try {
PhpSpreadsheetLite::make()
->setHeaders(['ID', 'Name', 'Email']) // Set the headers
->setContent([
[1, 'John Doe', 'john.doe@example.com'],
[2, 'Jane Smith', 'jane.smith@example.com'],
]) // Add your data
->setDirectory('/path/to/save') // Specify directory
->setFilename('example') // Specify file name
->setFileFormat(SpreadsheetFormat::XLSX) // Supported formats: XLSX, CSV
->createSpreadsheet();
echo "Spreadsheet created successfully.";
} catch (\Exception $exception) {
echo "Error: " . $exception->getMessage();
}
use CeytekLabs\PhpSpreadsheetLite\PhpSpreadsheetLite;
use CeytekLabs\PhpSpreadsheetLite\SpreadsheetFormat;
try {
$data = PhpSpreadsheetLite::make()
->setDirectory('/path/to/spreadsheet') // Specify directory
->setFilename('example') // Specify file name
->setFileFormat(SpreadsheetFormat::XLSX) // Match the file format
->readSpreadsheet();
print_r($data);
} catch (\Exception $exception) {
echo "Error: " . $exception->getMessage();
}
The SpreadsheetFormat enum helps you specify supported file formats consistently:
enum SpreadsheetFormat: string
{
case XLSX = 'xlsx';
case CSV = 'csv';
}
Feel free to submit a pull request or report an issue. Any contributions and feedback are highly appreciated!
This project is licensed under the MIT License.