Opening and reading an excel .xlsx file in python

[亡魂溺海] 提交于 2019-11-30 15:03:54

Maybe you could export your .xlsx to a .csv file?

Then you could try:

import csv
with open('file.csv','rb') as file:
    contents = csv.reader(file)
    [x for x in contents]

This may be useful: http://docs.python.org/2/library/csv.html#csv.reader

Hope that helps!

EDIT:

If you want to locate a spectific cell, such as F13, you could make a nested list like a matrix and them refer to each element:

import csv
with open('file.csv','rb') as file:
    contents = csv.reader(file)
    matrix = list()
    for row in contents:
        matrix.append(row)

And then access F13 with matrix[5][12].

P.S.: I did not test this. If "row" is a list with each cell as an element, you keep appending all lines to the matrix, so the first index is row number and the second is the column number.

it seems that you are on a Linux Distro. I had the same problem too and this does not happen with "xlwt" library but only with "xlrd". what I did is not the right way to solve this problem but it makes things work for the time being to hopefully have an answer to that question soon ;I have installed "xlrd" on Windows and took the folder and pasted it on Linux in the directory where my python code is and it worked.

Since I know other people will also be reading this -

You can install the following module (it's not there automatically) https://pypi.python.org/pypi/openpyxl

You can read the following to get a nice breakdown on how to use it

https://automatetheboringstuff.com/chapter12/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!