开发者

How to put HH:mm:ss formatted times in CSV so Excel formats them as regular text?

开发者 https://www.devze.com 2023-04-03 14:16 出处:网络
I\'m writing times into a CSV file time using the format HH:mm:ss.When excel opens the fileit automatically recognizes this column format as time.Is it possible to prevent Excel from doing this so the

I'm writing times into a CSV file time using the format HH:mm:ss. When excel opens the file it automatically recognizes this column format as time. Is it possible to prevent Excel from doing this so the column is 开发者_如何学运维formatted as regular text?

Thank you


There was recently a similar question on SuperUser: link

The same principle as the accepted answer can be employed here if all you want is a CSV that can be opened with Excel without the ill-effects of autoformatting. You'll need to write your values to the CSV in this format:

="yourdatetimehere"

Of course the downside is that the equal signs and quotation marks will be stored in your CSV as text. This means that this will probably cause problems for you if you plan to use the CSV in any context outside Excel. But as a hack to get around Excel's autoformatting, this should work.


You have no control over formatting in a CSV file, unless you want to go through the full custom-import setup in Excel each time.

If you want to force Excel to treat something as text, then use a proper Excel file, generated using PHPExcel

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号