How to get XLS file format value using PHPExcel

不羁岁月 提交于 2019-12-25 04:37:16

问题


I have XLS cells deference number formatted. this how look like my cells

  • E8: Date formatted cell
  • E9: Number formatted cell
  • E10: General formatted cell
  • E11: Percentage formatted cell
  • E12: Fraction formatted cell

I want to read these above cells data without any changes(Friday, May 10, 2013 , 41404.00, drfsdf, 1/2) i use below method for that but i didn't success every bellow method return for text value of the cells

$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);
   $rowIndex = $row->getRowIndex();
   $array_data[$rowIndex] = array('A' => '', 'B' => '');
   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();
      }
   }
}  

please help to get view value of the XLS file as Friday, May 10, 2013 , 41404.00, drfsdf, 1/2 in to the $array_data using PHPExcel.


回答1:


Get rid of the

$objReader->setReadDataOnly(true);

otherwise PHPExcel has no way of knowing whether a cell is formatted as a date or not

setReadDataOnly(true) tells PHPExcel to load only the raw data from each cell. As the only way MS Excel differentiates a date/time from a float is through the number format mask (not from the raw data), and you're telling PHPExcel not to read the number format masks, PHPExcel can't tell the diference, so all floats are simply treated as floats



来源:https://stackoverflow.com/questions/20046704/how-to-get-xls-file-format-value-using-phpexcel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!