Reading and Writing Excel (xlsx files) with Python

For most, basic tasks:

For Writing – xlsxwriter (don’t us xlwt, it doesn’t support xlsx Format.)
For Reading – xlrd (can read both xls and xlsx)

(There’s a library called xlwt for writing to xls, however it is old and doesn’t support the xlsx format, which provides advanced Excel file formatting. XlsxWriter creator, John McNamara, is actively involved in maintaining it. Both require same skill level to use. )

You can also use Pandas if you want to create graphs and charts and some advanced number crunching. (Pandas internally uses XlsxWriter modules to write the files and xlrd to read!)

XlsxWriter is 100% compatible with xlsx, so you can do charts, formulae, conditional formatting etc.

P.S. – The last x in xlsx stands for XML. xlsx is a zipped Open XML file.
Use xlsx wherever possible. xls is the old (proprietary) format, which doesn’t have some advanced features like conditional formatting or freezing col/rows etc.

 

Leave a Reply

Your email address will not be published. Required fields are marked *