Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Created September 9, 2014 19:19
Show Gist options
  • Save khoand0000/8e21a77952f3c451e1a6 to your computer and use it in GitHub Desktop.
Save khoand0000/8e21a77952f3c451e1a6 to your computer and use it in GitHub Desktop.
How to use PHPExcel
<?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