1. Go to this page and download the library: Download yidas/phpexcel-helper 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/ */
// Get a new PHPExcel object
$objPHPExcel = new \PHPExcel;
$objPHPExcel->getProperties()
->setCreator("Nick Tsai")
->setTitle("Office 2007 XLSX Document");
// Get the actived sheet object
$objPHPExcelSheet = $objPHPExcel->setActiveSheetIndex(0);
$objPHPExcelSheet->setTitle('Sheet');
$objPHPExcelSheet->setCellValue('A1', 'SN');
// Inject PHPExcel Object and Sheet Object to Helper
\PHPExcelHelper::newExcel($objPHPExcel)
->setSheet($objPHPExcelSheet)
->setRowOffset(1) // Point to 1nd row from 0
->addRows([
['1'],
['2'],
]);
\PHPExcelHelper::output();
\PHPExcelHelper::newExcel()
->setSheet(0, 'Sheet')
->addRow(['SN']);
// Get the PHPExcel object created by Helper
$objPHPExcel = \PHPExcelHelper::getExcel();
$objPHPExcel->getProperties()
->setCreator("Nick Tsai")
->setTitle("Office 2007 XLSX Document");
// Get the actived sheet object created by Helper
$objPHPExcelSheet = \PHPExcelHelper::getSheet();
$objPHPExcelSheet->setCellValue('A2', '1');
$objPHPExcelSheet->setCellValue('A3', '2');
\PHPExcelHelper::output();
\PHPExcelHelper::newExcel()
->setSheet(3, '4nd Sheet')
->addRow(['ID', 'Name'])
->addRows([
['1', 'Nick'],
]);
// Set another sheet object and switch to it
\PHPExcelHelper::setSheet(1, '2nd Sheet')
->addRow(['SN', 'Title'])
->addRows([
['1', 'Foo'],
]);
\PHPExcelHelper::output('MultiSheets');