2017-03-07 29 views
0

我使用PHPExcel阅读器读取Yii2应用程序中Exce文件的数据。 这是我使用的代码:我用它下面的一些源教程PHPExcel阅读器中三个bool值的用途是什么?

$objPHPExcel = new \PHPExcel(); 
     $fileName = Yii::getAlias('@webroot/trash/trash_vatout/') . $name; 
     $inputFiles = fopen(Yii::getAlias('@webroot/trash/trash_vatout/') . $name, "r"); 
     try { 
      $inputFileType = \PHPExcel_IOFactory::identify($fileName); 
      $objReader = \PHPExcel_IOFactory::createReader($inputFileType); 
      $objPHPExcel = $objReader->load($fileName); 
     } catch (Exception $ex) { 
      die('Error'); 
     } 
     $sheet = $objPHPExcel->getSheet(0); 
     $highestRow = $sheet->getHighestDataRow(); 
     $highestColumn = $sheet->getHighestDataColumn(); 
     $colNumber = PHPExcel_Cell::columnIndexFromString($highestColumn); 
     $col = $colNumber - 1; 
     $arrayData = []; 

    $bool1 = NULL;   //first bool value 
    $bool2 = NULL;   //second bool value 
    $bool3 = NULL;   //third bool value 
    for ($row = 1; $row <= $highestRow; ++$row) { 
    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, $bool1, $bool2, $bool3); 
    if (!is_null($rowData[0][$col])) { 
     $arrayData[] = array_map(function($values) { 
      $tempArrayKey = []; 
      foreach ($values as $key => $value) { 
       $newKey = $key + 1; 
       $tempArrayKey[] = $newKey . '_' . $value; 
      } 
      return $tempArrayKey; 
    }, $rowData); 
    } 
    } 

。 在行代码$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, $bool1, $bool2, $bool3);中,它已经设置了三个布尔值。在我的情况下,我将它们全部设置为NULL

任何人都知道bool值的实际目的是什么?

我试过manytimes读取文件,如果我没有错,第二布尔值设置为阅读Excel公式

但其他人怎么样?

谢谢。

+2

你好,我看你刚开始美丽的旅程到PHP语言。请不要忘记阅读文档有时候,像这样:http://hitautodestruct.github.io/PHPExcelAPIDocs/classes/PHPExcel_Worksheet.html#method_rangeToArray其中所有的解释一一。 – Yupik

+0

哦,我忘了一件事。您必须单击“从单元格范围创建数组”标题以扩展规范。玩得开心的朋友! – Yupik

回答

0

rangeToArray() method签名是

/** 
* Create array from a range of cells 
* 
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") 
* @param mixed $nullValue Value returned in the array entry if a cell doesn't exist 
* @param boolean $calculateFormulas Should formulas be calculated? 
* @param boolean $formatData Should formatting be applied to cell values? 
* @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero 
*        True - Return rows and columns indexed by their actual row and column IDs 
* @return array 
*/ 

所以

  • $bool1 - 混合$nullValue 值在阵列条目返回如果单元不存在(可以是任何数据类型/值)
  • $bool2 - 布尔值​​ 应该计算公式吗?
  • $bool3 - 布尔值$formatData 应该将格式应用于单元格值吗?