简体   繁体   中英

What are the purpose of three bool value in PHPExcel reader?

I'm using PHPExcel reader for read data from Exce file in my Yii2 application. This is the code that I've used:

$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);
   }
  }

I used it following tutorial from some source. In line code $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, $bool1, $bool2, $bool3); , it has been set three boolean value. In my case I set them all as NULL .

Anyone knows what are the purpose of the bool value actually?

I've tried manytimes to read file, if I'm not wrong, the second bool value is set for read Excel Formula .

But how about the others?

Thanks.

The signature for the rangeToArray() method is

/**
 * 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
 */

so

  • $bool1 - mixed $nullValue Value returned in the array entry if a cell doesn't exist (can be any datatype/value)
  • $bool2 - boolean $calculateFormulas Should formulas be calculated?
  • $bool3 - boolean $formatData Should formatting be applied to cell values?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM