简体   繁体   中英

Not able to open excel file in python using xlrd

I am using python 2.7 and the latest xlrd package.

import xlrd
xfile = xlrd.open_workbook("random_stuff.xlsx");

The above code gives me an error that says :

un(shallow)copyable object of type <type 'Element'>

and takes me to a file by the name of cElementTree.py which contains this :

# Wrapper module for _elementtree

from _elementtree import *

What is the error i simply don't get it. I am fairly new to python. I started learning about a month ago. EDIT : Using the location method :

import xlrd
file_location = "C:\Users\Tanmay\Documents\Visual Studio 2015\Projects\PythonApplication1\PythonApplication1\random_stuff.xlsx"
xfile = xlrd.open_workbook(file_location , r)

gives the following error :

[Errno 22] invalid mode ('rb') or filename: 'C:\\Users\\Tanmay\\Documents\\Visual Studio 2015\\Projects\\PythonApplication1\\PythonApplication1\random_stuff.xlsx'

你可以改用原始字符串吗?

file_location = r"C:\Users\Tanmay\Documents\Visual Studio 2015\Projects\PythonApplication1\PythonApplication1\random_stuff.xlsx"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM