程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php excel讀取,phpexcel

php excel讀取,phpexcel

編輯:關於PHP編程

php excel讀取,phpexcel


當然首先要判斷是否有文件和文件類型,接著把文件保存到某個路徑中

/**
 * 讀取excel數據
 * @author Red
 * @date
 * @param $filename 文件所在路徑+文件名
 * @param string $encode
 * @param $file_type
 * @return array
 */
function readExcel($filename, $encode = 'utf-8', $file_type)
{
    include './plugins/excel/PHPExcel.php';
    include './plugins/excel/PHPExcel/Reader/Excel2007.php';
    include './plugins/excel/PHPExcel/Writer/Excel5.php';
    include './plugins/excel/PHPExcel/Writer/Excel2007.php';

    if ($file_type == 'xlsx') {
        $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    } else {
        $objReader = PHPExcel_IOFactory::createReader('Excel5');
    }

    $objReader->setReadDataOnly(true);

    $objPHPExcel        = $objReader->load($filename);
    $objWorksheet       = $objPHPExcel->getActiveSheet();
    $hightestrow        = $objWorksheet->getHighestRow();
    $highestColumn      = $objWorksheet->getHighestColumn();
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $excelData          = array();
   //從第二行開始
    for ($row = 2; $row <= $hightestrow; $row++) {
        for ($col = 0; $col < $highestColumnIndex; $col++) {
            $excelData[$row][] = (string)$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
        }
    }

    return $excelData;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved