dpxw7293 2017-02-03 17:01
浏览 362
已采纳

导出后PHPExcel单元格格式不起作用

I have a PHP code that will export an array of data to excel. It is working fine but the formatting isn't working on the output. For example, I have an array value of 0:13:00 (it is in 24 hour format). What I want is to format it in excel to [mm]:ss so the output should be 13:00 after the export but the value remain as it is while when I look on the cell formatting in excel, the format is already in [mm]:ss. I also tried changing the value to 12 hour format (12:13:00 AM) but it also remain as it is after export. Can someone help me with this please.
Here is my code in formatting the cell using PHPExcel.

$sheet = $objPHPExcel->getActiveSheet();
$sheet->getStyle('C3:N199')->getNumberFormat()->setFormatCode('[mm]:ss');
  • 写回答

1条回答 默认 最新

  • duanji9481 2017-02-03 17:29
    关注

    You mean you have a string containing "0:13:00"? You need to convert it to an MS Excel Serialized timestamp for a number format code like [mm]:ss to have any meaning.... use

    $objPHPExcel->getActiveSheet()
        ->setCellValue('A1', 
            PHPExcel_Calculation_DateTime::TIMEVALUE('00:13:15')
        );
    $objPHPExcel->getActiveSheet()
        ->getStyle('A1')
        ->getNumberFormat()
        ->setFormatCode('[mm]:ss');
    

    as described in the PHPExcel documentation and examples

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部