14

Is there a Python module that writes Excel 2007+ files?
I'm interested in writing a file longer than 65535 lines and only Excel 2007+ supports it.

Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359

8 Answers8

17

Take a look at Eric' Gazoni's openpyxl project. The code can be found on bitbucket.

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
10

There are two libraries you can take a look at.

Python-xlsx and PyXLSX

EDIT: As the comments mention, for writing you check out openpyxl

user225312
  • 126,773
  • 69
  • 172
  • 181
  • 6
    -1 The OP wants to **write** Excel 2007+ files. Python-xlsx: "Tiny python code for parsing data **from** an Office Open XML Spreadsheet - xlsx"; pyXLSX: "pyXLSX - A python class library for **reading** Excel 2007 files" – John Machin Nov 23 '10 at 17:18
8

You should take a look at xlsxcessive. It's for writing xlsx files, and is, perhaps, a bit more pythonic.

chmullig
  • 13,006
  • 5
  • 35
  • 52
  • 1
    I prefere xlsxcessive for writing xlsx files, too. It supports merging cells, which is no supported by openpyxl. – guettli Aug 17 '11 at 09:05
  • Is this still being maintained? Commits on bitbucket seem to have come to a sudden stop (very regular until 2011-04-30 then nothing). – John Machin Mar 18 '12 at 11:01
  • It may not be. That's around the time when the developer changed jobs, so I imagine he stopped updating. :( – chmullig Mar 22 '12 at 18:00
  • For the record, openpyxl supports merged cells now. – John Y Jan 31 '13 at 22:55
7

The XlsxWriter Python module writes 2007+ xlsx files.

jmcnamara
  • 38,196
  • 6
  • 90
  • 108
1

If you are on Windows and have Excel 2007+ installed, you should be able to use pywin32 and COM to write XLSX files using almost the same code as you would would to write XLS files ... just change the "save as ...." part at the end.

Probably, you can also write XLSX files using Excel 2003 with the freely downloadable add-on kit but the number of rows per sheet would be limited to 64K.

John Machin
  • 81,303
  • 11
  • 141
  • 189
1

This should give an idea how to do that:

import xlsxwriter

workbook = xlsxwriter.Workbook("output_file.xlsx"))
# new sheet
worksheet = workbook.add_worksheet("sheet_name")
# Add a number format: 3 digits precision
precision = workbook.add_format({'num_format': '0.000'})

for(iterate your data):
    worksheet.write(row, col, title)
    worksheet.write_number(row, col, value, precision)
    ...

workbook.close()
J.K
  • 1,178
  • 10
  • 13
1

Pyvot: http://packages.python.org/Pyvot/tutorial.html, although it is only for Excel 2010+

cndnflyr
  • 163
  • 2
  • 14
googed
  • 11
  • 1
0

So you want to write xlsx file, into my mind the Microsoft.office.excel.interop dll come to my mind, but not use it on a server.

I know you can call dll from python : http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel(office.11).aspx

ykatchou
  • 3,667
  • 1
  • 22
  • 27