PHP code example of chenmobuys / easyexcel
1. Go to this page and download the library: Download chenmobuys/easyexcel 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/ */
chenmobuys / easyexcel example snippets
use EasyExcel\Factory;
use EasyExcel\Metadata\Style;
// read excel
$filename = "/path/to/sample.xlsx";
$reader = Factory::load($filename);
foreach ($reader->getRowIterator() as $row) {
$rowArray = $row->toArray();
}
// write excel
$filename = "/path/to/sample.xlsx";
$writer = Factory::open($filename);
$writer->addRow(["Foo", "Bar"])->close();
// write excel with style
$filename = "/path/to/sample.xlsx";
$writer = Factory::open($filename);
$style = Style::builder()
->setFontSize(12)
->setFontColor(Style\Color::RED)
->build();
$writer->addRow(["Foo", "Bar"], $style)->close();