1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<?php /** Include PHPExcel_IOFactory */ require_once (JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers/PHPExcel/Classes/PHPExcel/IOFactory.php'); // Read XLS file $objPHPExcel = PHPExcel_IOFactory::load($filepath); $rows = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); // Read CSV file $inputFileType = 'CSV'; $inputFileName = $filepath; $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); $worksheet = $objPHPExcel->getActiveSheet(); foreach ($worksheet->getRowIterator() as $row) { echo 'Row number: ' . $row->getRowIndex() . "\r\n"; $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set foreach ($cellIterator as $cell) { if (!is_null($cell)) { echo 'Cell: ' . $cell->getCoordinate() . ' - ' . $cell->getValue() . "\r\n"; } } } OR $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); //read from file $rows = array(); for ($row = 1; $row <= $highestRow; ++$row) { $file_data = array(); for ($col = 0; $col < $highestColumnIndex; ++$col) { $value=$objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); $file_data[$col]=trim($value); } $rows[] = $file_data; } ?> |