我正在使用phpexcel读取器在我的yii2应用程序中的exce文件中读取数据。这是我使用的代码:
$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值的目的是什么?
我已经尝试了很多时间来读取文件,如果我没有错,第二个bool value 是为读取 excel公式。
但是其他人怎么样?
谢谢。
rangetoArray()方法的签名是
/**
* 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
-混合$nullValue
如果单元不存在,则在数组条目中返回的值(可以是任何数据类型/值) -
$bool2
-布尔$calculateFormulas
应该计算公式吗? -
$bool3
-布尔$formatData
格式应应用于单元格值吗?