Writing to ms excel

John Machin sjmachin at lexicon.net
Sun Aug 31 02:18:19 CEST 2008

On Aug 31, 12:41 am, Marin Brkic <mbrkic at invalid_mail.adress> wrote:
> I'm trying to find a way to write data to excel cells (or to be more
> specific to an .xls file), let's say for the sake of argument, data
> readen from a file (although it will be calculated in the process).
> I've been searching, but couldn't find any examples which allows that.
> Do anyone knows of any ? All help is appreciated on this matter.
> Tutorials? Anything ...

It helps in situations like this to mention details of your
(1) what version of what operating system (Linux, OS X, Windows, etc)
(2) what version of Python
as the available solutions are often dependent on the answers.

For Python version 2.[345] on any platform, you can use xlwt, which is
as simple as this for writing a 1-worksheet Excel 97-to-2003 XLS file
(without any formatting):

def write_xls(file_name, sheet_name, data):
    import xlwt
    book = xlwt.Workbook()
    sheet = book.add_sheet(sheet_name)
    rowx = 0
    for row in data:
        rowx += 1
        for colx, value in enumerate(row):
            sheet.write(rowx, colx, value)
# data can be any of the following Python types: int, long, float,
decimal.Decimal, datetime.date, datetime.datetime, bool, str, and

xlwt is available from https://secure.simplistix.co.uk/svn/xlwt/trunk

I suggest that you join the python-excel group (http://
groups.google.com.au/group/python-excel?hl=en) or at least read some
of the questions and responses.



More information about the Python-list mailing list