如何使用php从xls准确读取09/09/2017? [英] how to read 09/09/2017 exactly from xls using php?
问题描述
var_dump($objPHPExcel->getActiveSheet()->getCell('B2')->getValue());
我尝试了上面的代码,我得到了"float(42987)"
作为输出.
我只想要那个单元格的确切值!
i tried the above code and i get "float(42987)"
as output.
i just want the exact value of that cell!
var_dump($objPHPExcel->getActiveSheet()->getCell('C2')->getValue());
执行此操作时,我得到正确的值"2017/09/12"
when i execute this i get the correct value "2017/09/12"
那么我如何从xls获取这种"09/09/2017"
格式的数据?
so how will i get the data's in this "09/09/2017"
format from xls?
编辑1 :
the data cannot be predicted ! it can be a string or date with different formats !
example : B2 can be 'string','09/09/2017','09-09-2017','2017/09/09','10/20-25/14'
EDIT 1 :
the data cannot be predicted ! it can be a string or date with different formats !
example : B2 can be 'string','09/09/2017','09-09-2017','2017/09/09','10/20-25/14'
像这个例子一样,任何数据都可以在那里!所以我只想要用户提供的单元格中的准确数据!
like this example any data can be there! so i just want exact data from the cell provided by the user!
编辑2 :我正在使用rangeToArray
for ($row = 2; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A'.$row.':' . $highestColumn.$row,NULL,TRUE,FALSE);
}
那么我将如何在rangeToArray
中实现->getFormattedValue()
?
so how will i implement ->getFormattedValue()
in rangeToArray
?
推荐答案
If you are using the rangeToArray()
method to get the data, then take a look at the arguments for 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
*/
因此,要获取rangeToArray()
返回的格式值,您需要将$formatData
参数设置为true
So to get the formatted values returned by rangeToArray()
you need to call it with the $formatData
argument set to true
$rowData = $sheet->rangeToArray('A'.$row.':' . $highestColumn.$row,NULL,TRUE,TRUE);
这篇关于如何使用php从xls准确读取09/09/2017?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!