PHP code example of adnzaki / excel-creator
1. Go to this page and download the library: Download adnzaki/excel-creator 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/ */
adnzaki / excel-creator example snippets
use ExcelTools\Writer;
$excel = new Writer();
$excel->save('hello_world.xlsx');
$style = [
'font' => [
'name' => 'Arial',
'size' => 10,
],
'borders' => [
'allBorders' => [
'borderStyle' => $excel->border::BORDER_THIN,
'color' => ['argb' => $excel->color::COLOR_BLACK],
],
]
];
$excel->applyStyle($style, 'A2:D10');
$data = [
['Name', 'City'],
['Zaki', 'Jakarta'],
['Dien', 'Bojonegoro']
];
$excel->fillCell($data, 'A1');
$excel->wrapText('B5');
$excel->mergeCells('A1:B1');
$excel->unmergeCells('A1:B1');
$excel->setColumnWidth('A', 20);
$excel->setMultipleColumnsWidth(['B', 'C'], 25);
$excel->setDefaultColumnWidth(15);
$excel->setRowHeight(3, 25);
$excel->setMultipleRowsHeight(['1' => 40, '3-5' => 25]);
$excel->setDefaultRowHeight(20);
$excel->setDefaultFont('Calibri', 11);
use ExcelTools\Reader;
$reader = new Reader();
$reader->loadFromFile('SampleFile.xlsx');
$data = $reader->getSheetData(true); // true = first row as headers
print_r($data);
$sheetNames = $reader->getSheetNames();
$reader->setActiveSheet('Sheet2');