Created
September 9, 2014 19:19
-
-
Save khoand0000/8e21a77952f3c451e1a6 to your computer and use it in GitHub Desktop.
How to use PHPExcel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* User: videde | |
* Date: 8/21/13 | |
* Time: 1:37 AM | |
*/ | |
set_include_path(dirname(__FILE__).'/Classes/'); | |
include 'PHPExcel/IOFactory.php'; | |
function action() { | |
$excel = 'xzy.xls'; | |
$objPHPExcel = PHPExcel_IOFactory::load($excel); | |
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); | |
foreach ($sheetData as $row){ | |
echo $row['A']; | |
} | |
} | |
// https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/07-Accessing-Cells.md | |
$objReader = PHPExcel_IOFactory::createReader('Excel2007'); | |
$objReader->setReadDataOnly(TRUE); | |
$objPHPExcel = $objReader->load("test.xlsx"); | |
$objWorksheet = $objPHPExcel->getActiveSheet(); | |
echo '<table>' . PHP_EOL; | |
foreach ($objWorksheet->getRowIterator() as $row) { | |
echo '<tr>' . PHP_EOL; | |
$cellIterator = $row->getCellIterator(); | |
$cellIterator->setIterateOnlyExistingCells(FALSE); // This loops through all cells, | |
// even if a cell value is not set. | |
// By default, only cells that have a value | |
// set will be iterated. | |
foreach ($cellIterator as $cell) { | |
echo '<td>' . | |
$cell->getValue() . | |
'</td>' . PHP_EOL; | |
} | |
echo '</tr>' . PHP_EOL; | |
} | |
echo '</table>' . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment