$tmp_file = $_FILES ['excel'] ['tmp_name']; //Temporary file $name = $_FILES['excel']['name']; //Upload file name Do different processing according to upload type
if ($file_type == 'xls') { $reader = PHPExcel_IOFactory::createReader('Excel5'); //Set in Excel5 format (Excel97-2003 workbook) } if ($file_type == 'xlsx') { $reader = new PHPExcel_Reader_Excel2007(); } read excel file
$PHPExcel = $reader->load($tmp_file, 'utf-8'); // load excel file $sheet = $PHPExcel->getSheet(0); // read the first sheet $highestRow = $sheet->getHighestRow(); // Get the total number of rows $highestColumn = $sheet->getHighestColumn(); // Get the total number of columns Save Excel data in an array
$data = array(); for ($rowIndex = 1; $rowIndex <= $highestRow; $rowIndex++) { //Loop to read the contents of each cell. Note that rows start at 1 and columns start at A for ($colIndex = 'A'; $colIndex <= $highestColumm; $colIndex++) { $addr = $colIndex . $rowIndex; $cell = $sheet->getCell($addr)->getValue(); if ($cell instanceof PHPExcel_RichText) { //Rich text conversion string $cell = $cell->__toString(); } $data[$rowIndex][$colIndex] = $cell; } }
echo $data; Process the data as needed. . .