doxd96148 2015-04-13 20:24
浏览 41
已采纳

PHP值日期xlsx到csv

I have an XLSX file with some cells that has a date value like: 13/04/2015 when I convert my XLSX to CSV the date value in my CSV becomes its value as: 42107

I need that the value be the same in both files like in XLSX (13/04/2015)

Here's my convert script

include ('./PHPExcel/Classes/PHPExcel.php');
$TypeFile="Excel2007";
$FilePath= "./assets/uploads/files/prf.xlsx";
$objReader = PHPExcel_IOFactory::createReader($TypeFile);
$objReader->setReadDataOnly(true);   
$objExcel = $objReader->load($FilePath);
$objCSV = PHPExcel_IOFactory::createWriter($objExcel, 'CSV');
$objCSV->setPreCalculateFormulas(false);
$objCSV->setDelimiter(','); 
$objCSV->setEnclosure('"');    
$objCSV->save('./assets/uploads/files/prf.csv');
  • 写回答

1条回答 默认 最新

  • douduiwei2831 2015-04-13 20:29
    关注

    Yes, it will

    A date in MS Excel is a number value like 42107, that represents a number of days since 1st January 1900, and the only thing that tells MS Excel (or PHPExcel) that it should be treated as a date is the number format mask that's applied to that cell.

    When you use

    $objReader->setReadDataOnly(true); 
    

    you're telling PHPExcel to read the raw data values from the cells, and ignore any number format masks (or indeed any styling) for cells, so that's what you're getting.

    If you want PHPExcel to treat the value as a date, then don't use $objReader->setReadDataOnly(true);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?