如何解决错误 – 加载文件“Excel2007”错误:无法打开Excel2007阅读! 使用PHPExcelFile读取excel文件?

myfile.xlsx是要打开的文件的名称。我已经使用PHPExcel库(一个非常常见的库),但我找不到代码来读取excel文件,并显示在句子或browser.Plz的帮助。

try { $inputFileType = PHPExcel_IOFactory::identify('myfile.xlsx'); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileType); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileType, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator(); $array_data = array(); foreach ($rowIterator as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); $rowIndex = $row->getRowIndex(); $array_data[$rowIndex] = array('A' => '', 'B' => '', 'C' => '', 'D' => '', 'E' => '', 'F' => '', 'G' => ''); foreach ($cellIterator as $cell) { if ('A' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } else if ('B' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } else if ('C' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } else if ('D' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } else if ('E' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } else if ('F' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } else if ('G' == $cell->getColumn()) { $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue(); } }} 

当您的文件被称为myfile.xlsx时,不要试图打开名为Excel2007的文件( $inputFileType的值)

 $objPHPExcel = $objReader->load('myfile.xlsx');