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();
}
}}
答案 0 :(得分:1)
当您的文件被调用Excel2007
$inputFileType
的文件(myfile.xlsx
的值)
$objPHPExcel = $objReader->load('myfile.xlsx');