最新消息: 新版网站上线了!!!

phpExcel读取excel的内容

require_once './Classes/PHPExcel.php';
$inputFileType = PHPExcel_IOFactory::identify('search.xlsx');
header("Content-type:text/html;charset=utf-8");
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
 
$objReader->setReadDataOnly(true);
 
/**  Load $inputFileName to a PHPExcel Object  **/
$objPHPExcel = $objReader->load('search.xlsx');
 
$total_sheets=$objPHPExcel->getSheetCount();
 
$allSheetName=$objPHPExcel->getSheetNames();
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
echo '<table width="1200" border="1" cellpadding="0" cellspacing="0">';
for ($row = 1; $row <= $highestRow;++$row)
{
echo "<tr>";
for ($col = 0; $col <$highestColumnIndex;++$col)
{
$date=$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
 
if($col==5&&$row>=1){
$date = $objWorksheet->getCell('F2')->getValue(); // 37231 (Excel date)
$date = PHPExcel_Shared_Date::ExcelToPHP($date); // 1007596800 (Unix time)
$date = date('Y-m-d H:i:s', $date); // 06.12.2001 (formatted date)
}
    if($col==5&&$row==1){
        $date =  $objWorksheet->getCellByColumnAndRow(5, 1)->getValue();
 
    }
echo "<td style='width:30%;overflow-y:auto;'>".$date."</td>";
 
 
 
}
echo "</tr>";
}


转载请注明:谷谷点程序 » phpExcel读取excel的内容