user1917407 user1917407 - 1 month ago 7
Python Question

How can I get a dictionary from the contents of a .xlsx file?

I'm trying to use

pyexcel
but am having an issue following the instructions. On the documentation, it says to run this code:

>>> import pyexcel
>>> import json
>>> book_dict = pyexcel.get_book_dict(file_name="book.xls")
>>> isinstance(book_dict, OrderedDict)
True
>>> for key, item in book_dict.items():
... print(json.dumps({key: item}))
{"Sheet 1": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]}
{"Sheet 2": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]}
{"Sheet 3": [["O", "P", "Q"], [3, 2, 1], [4, 3, 2]]}


However, my interpreter in Python 2.7 says that
get_book_dict
is not a valid attribute. Any ideas how I should proceed?

Answer Source

I exactly don't know the reason of the error but I got a workaround for you. Try:

>>> from pyexcel.core import *
>>> get_book_dict
>>> <function get_book_dict at 0x7fb8cc87d140>

I think there might be some problems with init.py