1. 去 https://pypi.python.org/pypi/xlrd/0.9.2下载xlrd-0.9.2.tar.gz
2. 解压安装,笔者用的macos,直接python setup.py install
3. 使用样例:
import xlrd
book = xlrd.open_workbook(fn)
#多少个sheet
print "The number of worksheets is", book.nsheets
#每个sheet的名字
print "Worksheet name(s):", book.sheet_names()
#得到第0个sheet
sh = book.sheet_by_index(0)
for rx in range(sh.nrows):
values = sh.row(rx)
for value in values:
print value.ctype, value.value #type(number, text), value
本文档主要介绍如何通过python对office excel进行读写操作,使用了xlrd、xlwt和xlutils模块。另外还演示了如何通过Tcl tcom包对excel操作。感兴趣的朋友可以过来看看
1
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号