PHPExcel格式列到日期格式3月14日 [英] PHPExcel format column to date format 14-Mar
问题描述
是否可以使用以下选定值用PHPExcel格式化列(C2:C50):
Is it possible to format a column (C2:C50) with PHPExcel with the following selected values:
我真的无法正常工作. 已经尝试过类似的内容:
I really can't get this to work.. Already tried something like:
$sheet->getStyle('C2:C50')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS);
但是当我查看一个单元格属性时,它说该单元格的格式如下:
But when I look a the cell properties it said the cell is formatted like:
推荐答案
PHPExcel仅具有一组有限的内置常量格式,但是您可以通过使用适当的格式将格式代码设置为任何有效(自定义)格式字符串:
PHPExcel only has a limited set of built-in constants for formats, but you can set the format code to any valid (custom) format just by using the appropriate string:
$sheet->getStyle('C2:C50')
->getNumberFormat()
->setFormatCode('d-mmm');
请注意,除了MS Excel特定的编写器(例如,不在CSV,HTML,PDF中)以外,其他编写器不支持诸如Woensdaag
和Maart
之类的特定于语言环境的日期/月份名称.
Note that locale-specific day/month names such as Woensdaag
and Maart
aren't supported by writers other than the MS Excel specific writers (ie. not in CSV, HTML, PDF)
大多数自定义格式的字符串都可以使用,尽管有些不明朗的字符串(如直接支持的$#,," M"
)可以以MS Excel本身以外的格式显示
Most custom format strings will work, though there are a few obscure ones such as $#,," M"
that aren't directly supported, for display in formats other than MS Excel itself
这篇关于PHPExcel格式列到日期格式3月14日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!