[python-win32] writing hyphenated values in csv
Tim Roberts
timr at probo.com
Sat May 23 02:58:00 CEST 2009
Emad Khan wrote:
>
> I am trying to write a hyphenated value in a csv file but I don't want
> this value to be auto corrected to a date. Whenever I write a value,
> for example, "3-10", it is changed to 03/10/2009 or 03-oct.
>
> How can I prevent this from happening. I would like to see the value
> remain to be "3-10".
You should be more specific. I, for example, understand that it is
Excel that is doing this, but you need to mention that. It's not really
a CSV or Python problem at all -- it's an Excel problem.
The answer, in this case, is to put an equals sign in front of the
quoted value. Thus this file:
123,3-10,"3-10",=3-10,="3-10"
gets imported as
123 10-Mar 10-Mar -7 3-10
Again, however, this is just an Excel quirk. If you need to import into
Excel a lot, you might consider switching to Excel's XML format. You
have a great deal more control in that case.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list