Reading and Writing Excel (xlsx) files with Python

Jan 2021 Update

For Writing: use xlsxwriter (don’t use xlwt, it doesn’t support xlsx format.)
For Reading: use openpyxl (xlrd removed the support for xlsx in Dec 2020 due to security concerns.)

openpyxl supports writing too! So you may do everything with a single library. Xlsxwriter is faster in writing though. XlsxWriter creator, John McNamara, is actively involved in maintaining it.

June 2019

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

Prefer xlsx over xls

Use xlsx wherever possible. xls is the old Microsoft proprietary format. The last x in xlsx stands for XML. xlsx is a zipped Open XML open source file format. xlsx provides advanced formatting of xlsx files, viz. provides charts, formulae, conditional formatting, freezing of row/columns etc.

Other libraries

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


Posted

in

,

Comments

Leave a Reply