dtpngq3378499 2017-04-10 16:34
浏览 341
已采纳

如何使用PhpExcel生成日期格式?

$date='30-09-11'
  $objPHPExcel->getActiveSheet()
   ->setCellValue(toAlphaNumber($tmpCOunt + 9) . $rowNbmr, $date)
   ->getStyle(toAlphaNumber($tmpCOunt + 9) . $rowNbmr )->applyFromArray( array( 'font'  => array('color' => array('rgb' => '000000')) ))
    ->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14 )

                    ;

on Excel the cell shows that it is a "Date" but I can't manipulate it before I select the cell and press any key, then automatically it will align to the right and I become able to manipulate as a date.

  • 写回答

1条回答 默认 最新

  • duanjian4331 2017-04-10 17:02
    关注

    '30-09-11' is not a date. It might look like a date to a human; but to a computer it is nothing more than a string. To tell PHPExcel that it is a date, you have to convert it to something that the computer will recognise as a date - in this case, a MS Excel serialized timestamp (which is basically a count of the number of days since 1st January 1900.

    PHPExcel provides functionality too do just that, namely the PHPToExcel() method in the PHPExcel_Shared_Date class.

    However, you may also need to explain what your date string represents, e.g. is it 30th September 1911 or 2011? Is it 11th September 1930 or 2030? You need to sort out that ambiguity, because neither PHP nor PHPExcel cannot automagically understand what you mean by this ambiguous string, even when you do tell them that it's a date.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!