简体   繁体   中英

How to get XLS file format value using PHPExcel

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

XLS文件的单元格

  • 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.

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

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