Create Excel Files without COM

Noah Spurrier noah at noah.org
Wed Apr 10 11:02:17 EDT 2002


CSV is good because Excel does not make you through an import process.
The .CSV extension is registered with Excel when you install office. It
opens up almost
as if it were a regular spreadsheet (although it does give you warnings when
you try to save).
Tab and pipe | delimited files are not quote as good. Excel can read them
easily, but you have
to go through the import process every time... None of this is good if you
want to store
formulas, graphs, or formatted reports. It's good for basic data
interchange. Also I have
found that most naive users can be trained to export Excel into CSV format.

There are some rules for being Excel compatible.
    1. Any fields that contain commas must be quoted with double quotes.
    2. If a field contains a double quote then first you must double quote
        the entire FIELD and then the double quotes
        must be DOUBLE DOUBLE quoted.
            "ABC"  -->  """ABC"""
            AB"C"D  -->  "AB""C""D"
    3. If you EXPORT CSV format note that Excel has a weird property or bug
        where it will truncate trailing enpty fields (but not always! I
don't know if there is a rule).
        So a table like this:
            A, B, C, D
            A, B, ,
            A, B, C, D
        May get exported like this:
            A, B, C, D
            A, B
            A, B, C, D

Example.csv:
    A,"B,C","""D""",E,"F,G,""H""",I,"""",J,"""""",K
Will be read into these fields (converted into rows):
    A
    B,C
    "D"
    E
    F,G,"H"
    I
    "
    J
    ""
    K

Yours,
Noah

----- Original Message -----
From: "Stefan Heimann" <stefan.heimann at web.de>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, April 10, 2002 7:07 AM
Subject: Re: Create Excel Files without COM


> Thomas Guettler <st-newsgroups at thomas-guettler.de> wrote::
>
> > Hi!
> >
> > Is there something like WriteExcel from perl in python?
> > I need to generate an MS-Excel file. I don't want to use
> > COM although it will run on windows.
> >
> > The data is simple. Just text in columns and rows.
>
> What about CSV?
>
> Bye
>   Stefan
>






More information about the Python-list mailing list