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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵