I want to parse excel document to lists in Python. Is there a python library which is helpful for this action? And what functions are relevant in that library?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
xlrd is great for simple tasks, but if you need to work with any of Excel's deeper functionality (macros, advanced plotting, etc), and you are working on a windows machine, you can use the pywin32 library to control the win32com layer. This provides access to just about everything that can be controlled via macros / Visual Basic.
pyExcelerator does not seem to be maintained any more, but I have been using it for quite some time and have come to really like it.
Key Points:
Update
All of my new projects have moved to xlrd.
You're best bet for parsing Excel files would be the xlrd library. The python-excel.org site has links and examples for xlrd and related python excel libraries, including a pdf document that has some good examples of using xlrd. Of course, there are also lots of related xlrd questions on StackOverflow that might be of use.
One caveat with the xlrd library is that it will only work withxls
(Excel 2003 and earlier versions of excel) file formats and not the more recentxlsx
file format. There is a newer library openpyxl for dealing with thexlsx
, but I have never used it.UPDATE: As per John's comment, the xlrd library now supports both
xls
andxlsx
file formats.Hope that helps.
openpyxl is a great library and supports read/write to 2010 xlsx files.
sample parsing code
sample writing code
you can read more here: https://openpyxl.readthedocs.io/en/stable/index.html
The pandas library has a quick and easy way to read excel. If it's mostly just data and nothing too complicated it'll work:
It reads it into a pandas DataFrame, which is handy for data munging, etc.
To go to a list:
If you have multiple tables and things in each worksheet then you may want to use another library such as xlrd or openpyxl.
If you want to parse
xlsx
try python-xlsx