Windows下安装xlrd

标签:
pythonxlrdwindowsexcel |
分类: Python |
windows下使用python读取Excel表格,需要工具,找到了xlrd这个库,在windows下安装过程如下:
value =
sheet.row_values(row)
print value
首先是下载地址:
这是现在的最新版本,支持的Python版本为2.6, 2.7,
3.2+,在下载页面选择xlrd-1.0.0.tar.gz 的source文件下载,不要下载whl文件(嗯,没弄明白whl文件做啥用的,有高手的话请指点)
然后,解压下载的安装包到目录
最后是用cmd,进入到安装包的根目录下,如cd
一大串目录\xlrd-1.0.0
python setup.py install
running install
running bdist_egg
running egg_info
writing xlrd.egg-info\PKG-INFO
writing top-level names to xlrd.egg-info\top_level.txt
writing dependency_links to
xlrd.egg-info\dependency_links.txt
reading manifest file 'xlrd.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'README.html'
writing manifest file 'xlrd.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\xlrd
copying xlrd\biffh.py -> build\lib\xlrd
copying xlrd\book.py -> build\lib\xlrd
copying xlrd\compdoc.py -> build\lib\xlrd
copying xlrd\formatting.py -> build\lib\xlrd
copying xlrd\formula.py -> build\lib\xlrd
copying xlrd\info.py -> build\lib\xlrd
copying xlrd\licences.py -> build\lib\xlrd
copying xlrd\sheet.py -> build\lib\xlrd
copying xlrd\timemachine.py -> build\lib\xlrd
copying xlrd\xldate.py -> build\lib\xlrd
copying xlrd\xlsx.py -> build\lib\xlrd
copying xlrd\__init__.py -> build\lib\xlrd
creating build\lib\xlrd\doc
copying xlrd\doc\compdoc.html -> build\lib\xlrd\doc
copying xlrd\doc\xlrd.html -> build\lib\xlrd\doc
creating build\lib\xlrd\examples
copying xlrd\examples\namesdemo.xls ->
build\lib\xlrd\examples
copying xlrd\examples\xlrdnameAPIdemo.py ->
build\lib\xlrd\examples
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\biffh.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\book.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\compdoc.py ->
build\bdist.win-amd64\egg\xlrd
creating build\bdist.win-amd64\egg\xlrd\doc
copying build\lib\xlrd\doc\compdoc.html ->
build\bdist.win-amd64\egg\xlrd\doc
copying build\lib\xlrd\doc\xlrd.html ->
build\bdist.win-amd64\egg\xlrd\doc
creating build\bdist.win-amd64\egg\xlrd\examples
copying build\lib\xlrd\examples\namesdemo.xls ->
build\bdist.win-amd64\egg\xlrd\
examples
copying build\lib\xlrd\examples\xlrdnameAPIdemo.py ->
build\bdist.win-amd64\egg\
xlrd\examples
copying build\lib\xlrd\formatting.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\formula.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\info.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\licences.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\sheet.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\timemachine.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\xldate.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\xlsx.py ->
build\bdist.win-amd64\egg\xlrd
copying build\lib\xlrd\__init__.py ->
build\bdist.win-amd64\egg\xlrd
byte-compiling build\bdist.win-amd64\egg\xlrd\biffh.py to
biffh.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\book.py to
book.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\compdoc.py to
compdoc.pyc
byte-compiling
build\bdist.win-amd64\egg\xlrd\examples\xlrdnameAPIdemo.py to
xlr
dnameAPIdemo.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\formatting.py to
formatting.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\formula.py to
formula.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\info.py to
info.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\licences.py to
licences.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\sheet.py to
sheet.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\timemachine.py
to timemachine.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\xldate.py to
xldate.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\xlsx.py to
xlsx.pyc
byte-compiling build\bdist.win-amd64\egg\xlrd\__init__.py to
__init__.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
installing scripts to
build\bdist.win-amd64\egg\EGG-INFO\scripts
running install_scripts
running build_scripts
creating build\scripts-2.7
copying and adjusting scripts\runxlrd.py ->
build\scripts-2.7
creating build\bdist.win-amd64\egg\EGG-INFO\scripts
copying build\scripts-2.7\runxlrd.py ->
build\bdist.win-amd64\egg\EGG-INFO\scrip
ts
copying xlrd.egg-info\PKG-INFO ->
build\bdist.win-amd64\egg\EGG-INFO
copying xlrd.egg-info\SOURCES.txt ->
build\bdist.win-amd64\egg\EGG-INFO
copying xlrd.egg-info\dependency_links.txt ->
build\bdist.win-amd64\egg\EGG-INFO
copying xlrd.egg-info\top_level.txt ->
build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
xlrd.xlsx: module references __file__
creating dist
creating 'dist\xlrd-1.0.0-py2.7.egg' and adding
'build\bdist.win-amd64\egg' to i
t
removing 'build\bdist.win-amd64\egg' (and everything under
it)
Processing xlrd-1.0.0-py2.7.egg
creating
c:\python27\lib\site-packages\xlrd-1.0.0-py2.7.egg
Extracting xlrd-1.0.0-py2.7.egg to
c:\python27\lib\site-packages
Adding xlrd 1.0.0 to easy-install.pth file
error: [Errno 2] No such file or directory:
'C:\\Python27\\lib\\site-packages\\s
etuptools\\script.tmpl'
运行完成后,可以在C盘创建一个test.xls文件,里面附上部分内容,然后用下列代码测试是否安装成功
import xlrd
filename = 'C:\\test.xls'
data = xlrd.open_workbook(filename)
sheetname = data.sheet_names()
sheet = data.sheet_by_index(0)
rows = sheet.nrows
cols = sheet.ncols
for row in range(rows):
参考资料
更多Python支持Excel读写的库