无法从数组中检索数据

时间:2016-07-28 14:44:16

标签: php arrays phpexcel

我正在尝试解析Excel文件。我能够获得excel的单个单元格的内容。我无法将从单元格中获取的数据添加到数组中。

    function parseExcel($inputFileName){
    $mh = new MainHandler;
    //  Read your Excel workbook
    try {
        $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
        $objReader = PHPExcel_IOFactory::createReader($inputFileType);
        $objPHPExcel = $objReader->load($inputFileName);
    }catch(Exception $e) {
      die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
    }

    $Arr = array();
   //  Get worksheet dimensions
   $sheet = $objPHPExcel->getActiveSheet();
   $highestRow = $sheet->getHighestRow();
   $highestColumn = $sheet->getHighestColumn();

  for ($row = 1; $row <= $highestRow; $row++){

    $myArray = array();

    for($col = 'A' ; $col <= $highestColumn ; $col++){
       $a = $sheet->getCell($col.$row);
       // echo "\n".$a;
       $myArray[] = $a;
    }
    // $Arr[] = $myArray;
   echo json_encode($myArray);
 }
 // echo json_encode($Arr);
}

我得到的输出是

  [{},{},{},{},{}][{},{},{},{},{}][{},{},{},{},{}]

如何将填充的数组作为输出?

0 个答案:

没有答案