PHP code example of ceytek-labs / php-spreadsheet-lite
1. Go to this page and download the library: Download ceytek-labs/php-spreadsheet-lite 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/ */
ceytek-labs / php-spreadsheet-lite example snippets
use CeytekLabs\PhpSpreadsheetLite\PhpSpreadsheetLite;
use CeytekLabs\PhpSpreadsheetLite\SpreadsheetFormat;
try {
PhpSpreadsheetLite::make()
->setHeaders(['ID', 'Name', 'Email']) // Set the headers
->setContent([
[1, 'John Doe', '[email protected]'],
[2, 'Jane Smith', '[email protected]'],
]) // 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();
}
enum SpreadsheetFormat: string
{
case XLSX = 'xlsx';
case CSV = 'csv';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.