PHPExcel需要日期dd/mm/yy [英] PHPExcel date required dd/MM/yy

查看:162
本文介绍了PHPExcel需要日期dd/mm/yy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPExcel Lib下载excel表格,并要求列日期格式如25-May-17而不是我的excel下载表格中的25-05-17.

I am using PHPExcel Lib to download excel sheet and have required the column date format like 25-May-17 instead of 25-05-17 in my download excel sheet.

我能够添加25-05-17的数字格式,但不像17年5月25日,下面是我的代码.

I was able to added number format 25-05-17 but not like 25-May-17 and below is my code like.

      $objPHPExcel->getActiveSheet()
    ->getStyle('V'.$i)
    ->getNumberFormat()
    ->setFormatCode(
        PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY
    );

我在Lib类中找不到常量

I can not find the constant in Lib class

const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd';
const FORMAT_DATE_YYYYMMDD = 'yy-mm-dd';
const FORMAT_DATE_DDMMYYYY = 'dd/mm/yy';
const FORMAT_DATE_DMYSLASH = 'd/m/y';
const FORMAT_DATE_DMYMINUS = 'd-m-y';

可以帮我设置日期,例如d-M-yy(17年5月25日)吗?

Can some please help me on this to set date like d-M-yy(25-May-17)?.

推荐答案

您不受预定义常量的约束;这些只是MS Excel可以识别的一些格式字符串...可能的掩码的完整列表将过多....并且不必要...您要做的就是将字符串值传递给setFormatCode()方法,因此您可以传递字符串文字.

You're not constrained by the predefined constants; those are just some of the format strings that MS Excel recognises... a comprehensive list of ever possible mask would be excessive.... and unnecessary... all you're doing is passing a string value to the setFormatCode() method, so you can pass a string literal.

所需格式的MS Excel掩码为dd-mmm-yyyy,您可以将其简单地设置为字符串文字,而不使用任何常量:

The MS Excel mask for the format that you want is dd-mmm-yyyy, and you can set that simply as a string literal rather than using any constant:

$objPHPExcel->getActiveSheet()
    ->getStyle('V'.$i)
    ->getNumberFormat()
    ->setFormatCode('dd-mmm-yyyy');

请注意,MS Excel本身具有用于数字格式代码的自定义"选项,该选项允许您以完全相同的方式设置字符串文字.

Note that MS Excel itself has a "custom" option for number format codes, which allows you to set a string literal in exactly the same way

这篇关于PHPExcel需要日期dd/mm/yy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆