dpxw7293 2017-02-04 01:01
浏览 361
已采纳

导出后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-04 01: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 Windows Script Host 无法找到脚本文件"C:\ProgramData\Player800\Cotrl.vbs”
  • ¥15 matlab自定义损失函数
  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图