Created
October 9, 2017 15:27
-
-
Save mehrshaddarzi/b463fcb5c2399ba3f5da2d5fe7fc95a8 to your computer and use it in GitHub Desktop.
Load Excel file in php with 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
require_once str_replace("\\","/",get_template_directory()) . '/includes/phpexcel/PHPExcel.php'; | |
// Create new PHPExcel object | |
//$objPHPExcel = new PHPExcel(); | |
// Create new PHPExcel object | |
$upload_dir = str_replace("\\","/",wp_upload_dir()['basedir']); | |
try { | |
$objPHPExcel = PHPExcel_IOFactory::load($upload_dir.'/t.xlsx'); | |
$dataArr = array(); | |
foreach ( $objPHPExcel->getWorksheetIterator() as $worksheet ) { | |
$worksheetTitle = $worksheet->getTitle(); | |
$highestRow = $worksheet->getHighestRow(); // e.g. 10 | |
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F' | |
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString( $highestColumn ); | |
for ( $row = 1; $row <= $highestRow; ++ $row ) { | |
for ( $col = 0; $col < $highestColumnIndex; ++ $col ) { | |
$cell = $worksheet->getCellByColumnAndRow( $col, $row ); | |
$val = $cell->getValue(); | |
$dataArr[ $row ][ $col ] = $val; | |
} | |
} | |
} | |
} catch (ArithmeticError | Exception $e) { | |
echo 'lhata'; | |
} | |
echo '<pre>'; | |
print_r($dataArr); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment