PHPExcel Excel 自动日期格式
我正在使用 PHPExcel 创建 Excel 文件,并且有一些保留日期值的“日期”列。然而,PHPExcel 强制我定义一个日期格式来处理日期字段。例如
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';
const FORMAT_DATE_DMMINUS = 'd-m';
const FORMAT_DATE_MYMINUS = 'm-y';
const FORMAT_DATE_XLSX14 = 'mm-dd-yy';
const FORMAT_DATE_XLSX15 = 'd-mmm-yy';
const FORMAT_DATE_XLSX16 = 'd-mmm';
,但是,这是有限的,因为您必须使用这些格式之一。我想要的是,将日期提供给 PHPExcel 而无需格式化(或使用某些特殊的格式化类型),Excel 将根据用户当前的区域设置显示它。如果我使用其中一种格式,居住在美国的人会读取他不熟悉的不同时间格式,或者居住在不同国家/地区的用户会读取相同的情况。简而言之,Excel 必须以某种方式显示用户当前区域设置中的日期。这有可能吗?我用谷歌搜索但没有机会。
谢谢。
I'm using PHPExcel to create Excel files and I have some "Date" columns which keeps the date values. However, PHPExcel forces me to define a date format to work with the date fields. For example
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';
const FORMAT_DATE_DMMINUS = 'd-m';
const FORMAT_DATE_MYMINUS = 'm-y';
const FORMAT_DATE_XLSX14 = 'mm-dd-yy';
const FORMAT_DATE_XLSX15 = 'd-mmm-yy';
const FORMAT_DATE_XLSX16 = 'd-mmm';
However, this is limited since you have to use one of these formats. What I want is, giving the date to PHPExcel without formatting (or with some special formatting type) and Excel would show it according to users current locale. If I use one of this formats the guy lives in USA would read a different time format to which he is not familiar to or the same situation for users who lives in different countries. In short, somehow excel must show the date in current locale of the user. Is this possible somehow? I googled but no chance.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不限于使用常量。正如您可以在 MS Excel 本身中定义日期的自定义格式掩码一样,您也可以在 PHPExcel 中执行此操作。您只需自己定义掩蔽刺痛即可。
但是,当基于 MS Excel 区域设置在 MS Excel 中查看文件时,您无法自动更改该日期格式掩码。
MS Excel 是否为您提供此选项?如果是这样,您将如何在 MS Excel 中执行此操作?我不知道Excel的每一个功能,所以也许有可能;但我不知道你会怎么做。
You aren't restricted to using the constants. In the same way as you can define custom format masks for dates in MS Excel itself, you can do so in PHPExcel as well. You just have to define the masking sting yourself.
But you can't automatically change that date format mask when a file is viewed in MS Excel based on the MS Excel locale.
Does MS Excel give you this option? If so, how would you do it in MS Excel? I don't know every single feature of Excel, so it may be possible; but I'm not aware of how you would do it.