1. 程式人生 > >YII中使用PHPExcel匯入匯出

YII中使用PHPExcel匯入匯出

   $file = CUploadedFile::getInstance($model,'brand_model_file');
   var_dump($file->getType());
   if(in_array($file->getType(),array('application/vnd.ms-excel','application/excel','application/msexcel','application/kset')) )
   {
    $excelFile = $file->getTempName();
    //$phpexcel = new PHPExcel;
    $excelReader = PHPExcel_IOFactory::createReader('Excel5');
    $phpexcel = $excelReader->load($excelFile)->getSheet(0);
    $total_line = $phpexcel->getHighestRow();
    $total_column = $phpexcel->getHighestColumn();
    $allData = array();
    for ($row = 1; $row <= $total_line; $row++) {
     $data = array();
     for ($column = 'A'; $column <= $total_column; $column++) {
      $data[] = trim($phpexcel->getCell($column.$row) -> getValue());
     }
     array_push($allData, $data);
    }
    print_r($allData);