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 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?