2017 © Pedro Peláez
 

library phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

image

yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  • Sunday, February 25, 2018
  • by yidas
  • Repository
  • 2 Watchers
  • 1 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 11 % Grown

The README.md

PHPExcel Helper

Creating Excel with easy and artistic way based on PHPExcel, (*1)

Latest Stable Version Latest Unstable Version License, (*2)

PHPExcel is no longer maintained and should not be used anymore., (*3)

You should migrate to this library's successor yidas/phpspreadsheet-helper., (*4)


OUTLINE


DEMONSTRATION

\PHPExcelHelper::newExcel()
    ->addRow(['ID', 'Name', 'Email'])
    ->addRows([
        ['1', 'Nick','myintaer@gmail.com'],
        ['2', 'Eric','eric@.....'],
    ])
    ->output('My Excel');

INSTALLATION

Run Composer in your project:, (*8)

composer require yidas/phpexcel-helper

Then you could call it after Composer is loaded depended on your PHP framework:, (*9)

require __DIR__ . '/vendor/autoload.php';

\PHPExcelHelper::newExcel();

USAGE

Merge Cells

\PHPExcelHelper::newExcel()
    ->addRows([
        [['value'=>'SN', 'row'=>2], ['value'=>'Language', 'col'=>2], ['value'=>'Block', 'row'=>2, 'col'=>2]],
        ['','English','繁體中文',['skip'=>2]],
    ])
    ->addRows([
        ['1', 'Computer','電腦','#15'],
        ['2', 'Phone','手機','#4','#62'],
    ])
    ->output('Merged Excel');

PHPExcel & Sheet Object

// 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();

Multiple Sheets

\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');

Map of Coordinates & Ranges

\PHPExcelHelper::newExcel()
    ->addRows([
        [
            ['value'=>'SN', 'row'=>2, 'key'=>'sn'], 
            ['value'=>'Language', 'col'=>2, 'key'=>'lang'], 
            ['value'=>'Block', 'row'=>2, 'col'=>2, 'key'=>'block'],
        ],
        [   
            '',
            ['value'=>'English', 'key'=>'lang-en'],
            ['value'=>'繁體中文', 'key'=>'lang-zh'],
            ['skip'=>2, 'key'=>'block-skip'],
        ],
    ])
    ->addRows([
        ['1', 'Computer','電腦','#15'],
        ['2', 'Phone','手機','#4','#62'],
    ]);
// ->output('Merged Excel');  

print_r(\PHPExcelHelper::getCoordinateMap());
print_r(\PHPExcelHelper::getRangeMap());
// print_r(\PHPExcelHelper::getColumnMap());
// print_r(\PHPExcelHelper::getRowMap());
echo "sn start cell: ". \PHPExcelHelper::getCoordinateMap('sn');
echo "\nsn start column: ". \PHPExcelHelper::getColumnMap('sn');
echo "\nsn start row: ". \PHPExcelHelper::getRowMap('sn');
echo "\nsn range: ". \PHPExcelHelper::getRangeMap('sn');
echo "\nAll range: ". \PHPExcelHelper::getRangeAll(); 

The result could be:, (*10)

Array
(
    [sn] => A1
    [lang] => B1
    [block] => D1
    [lang-en] => B2
    [lang-zh] => C2
    [block-skip] => D2
)
Array
(
    [sn] => A1:A2
    [lang] => B1:C1
    [block] => D1:E2
    [lang-en] => B2:B2
    [lang-zh] => C2:C2
    [block-skip] => D2:E2
)
sn start cell: A1
sn start column: A
sn start row: 1
sn range: A1:A2
All range: A1:E4

Cells Format

  • setWrapText(): Set to all cells by default
  • setAutoSize(): Set to all cells(columns) by default
\PHPExcelHelper::newExcel()
    ->addRow(['Title', 'Content'])
    ->addRows([
        ['Basic Plan', "*Interface\n*Search Tool"],
        ['Advanced Plan', "*Interface\n*Search Tool\n*Statistics"],
    ])
    ->setWrapText()
    // ->setWrapText('B2')
    ->setAutoSize()
    // ->setAutoSize('B')
    ->output('Formatted Excel');  

The Versions

25/02 2018

dev-master

9999999-dev https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper

07/02 2018

1.3.1

1.3.1.0 https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper

08/12 2017

1.3.0

1.3.0.0 https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper

08/12 2017

1.2.1

1.2.1.0 https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper

07/12 2017

1.2.0

1.2.0.0 https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper

05/12 2017

1.1.0

1.1.0.0 https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper

03/12 2017

1.0.0

1.0.0.0 https://github.com/yidas/phpexcel-helper

Creating Excel with easy and artistic way based on PHPExcel

  Sources   Download

MIT

The Requires

 

php excel sheet phpexcel phpexcel helper