1. Go to this page and download the library: Download royfee/spreadsheet 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/ */
\yidas\phpSpreadsheet\Helper::newSpreadsheet()
// Set width as 25 to all cells of this row
->addRow([['value'=>'ID'], ['value'=>'Name'], ['value'=>'Email']], ['width'=>25]);
public static self addRows(array $data, array $rowAttributes=null)
// Get a new PhpSpreadsheet object
$objSpreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet;
$objSpreadsheet->getProperties()
->setCreator("Nick Tsai")
->setTitle("Office 2007 XLSX Document");
// Get the actived sheet object from PhpSpreadsheet
$objSheet = $objSpreadsheet->setActiveSheetIndex(0);
$objSheet->setTitle('Sheet');
$objSheet->setCellValue('A1', 'SN');
// Inject PhpSpreadsheet Object and Sheet Object to Helper
\yidas\phpSpreadsheet\Helper::newSpreadsheet($objSpreadsheet)
->setSheet($objSheet)
->setRowOffset(1) // Point to 1nd row from 0
->addRows([
['1'],
['2'],
])
->output();
use \yidas\phpSpreadsheet\Helper;
Helper::newSpreadsheet()
->setSheet(0, 'Sheet')
->addRow(['SN']);
// Get the PhpSpreadsheet object created by Helper
$objSpreadsheet = Helper::getSpreadsheet();
$objSpreadsheet->getProperties()
->setCreator("Nick Tsai")
->setTitle("Office 2007 XLSX Document");
// Get the actived sheet object created by Helper
$objSheet = Helper::getSheet();
$objSheet->setCellValue('A2', '1');
$objSheet->setCellValue('A3', '2');
Helper::output();
public static self setSheet($sheet=0, $title=NULL, $normalizeTitle=false)
public static object getSheet($identity=null, $autoCreate=false)
use \yidas\phpSpreadsheet\Helper;
Helper::newSpreadsheet()
->setSheet(0, 'First Sheet')
->addRow(['Sheet Index', 'Sheet Count'])
->addRows([
[Helper::getActiveSheetIndex(), Helper::getSheetCount()],
]);
// Set another sheet object without giving index
Helper::setSheet(null, '2nd Sheet')
->addRow(['Sheet Index', 'Sheet Count'])
->addRows([
[Helper::getActiveSheetIndex(), Helper::getSheetCount()],
]);
// Get a sheet which does not exsit with auto creating it
$obj = Helper::getSheet('3nd Sheet', true);
// Set a sheet with the title which has been auto-normalized
Helper::setSheet(null, '*This [sheet] name has been auto-nomalizing', true)
->addRow(['Sheet Index', 'Sheet Count'])
->addRows([
[Helper::getActiveSheetIndex(), Helper::getSheetCount()],
]);
Helper::output('MultiSheets');