I read XLS file using PHPExcel. There is cells date column. that data column has two type of cells (Date and Text type cells).
I need to get view value of the cells in the XLS file. So before get value of the cell i want to decided whether that cell is Date cell or Text cell.
How can i get view value of the XLS file cells. Is There method like getCellType(), getViewValueOfCell() or any other method for get view value of cell?
Note: $cell->getType is not a real method in PHPExcel. this pseudo method.
please suggest best logic/method for bellow cell read.
// read view value form date column
if($cell->getType == 'Date'){
$array_data[$rowIndex][$cell->getColumn()] = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'YYYY-MM-DD');
}
else if($cell->getType == 'Text'){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
}
this my all XLS read function
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file_path);
$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
$array_data = array();
foreach ($rowIterator as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
// if(1 == $row->getRowIndex ()) continue;//skip first row
$rowIndex = $row->getRowIndex();
$array_data[$rowIndex] = array('A' => '', 'B' => '', 'C' => '', 'D' => '');
foreach ($cellIterator as $cell) {
if ('A' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('B' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
} else if ('C' == $cell->getColumn()) {
// read view value form date column
if($cell->getType == 'Date'){
$array_data[$rowIndex][$cell->getColumn()] = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'YYYY-MM-DD');
}
else if($cell->getType == 'Text'){
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
}
} else if ('D' == $cell->getColumn()) {
$array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
}
}
}