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
精彩评论