xlrd 是用于自 Excel 文件读取数据和格式化信息的库从历史
.xls
格式。
警告
此库将不再读取任何内容除了
.xls
文件。有关读取更新文件格式的替代,请参阅
http://www.python-excel.org/
.
以下也不支持,但会安全且可靠地被忽略:
图表、宏、图片、任何其他嵌入对象、 包括 嵌入工作表。
VBA 模块
公式,但提取公式计算的结果。
注释
超链接
自动过滤、高级过滤、数据透视表、条件格式化、数据验证
此库不支持口令保护文件,且无法读取。
快速入门:
import xlrd
book = xlrd.open_workbook("myfile.xls")
print("The number of worksheets is {0}".format(book.nsheets))
print("Worksheet name(s): {0}".format(book.sheet_names()))
sh = book.sheet_by_index(0)
print("{0} {1} {2}".format(sh.name, sh.nrows, sh.ncols))
print("Cell D30 is {0}".format(sh.cell_value(rowx=29, colx=3)))
for rx in range(sh.nrows):
print(sh.row(rx))
从命令行,这将展示每个文件中每个工作表的第一、第二及最后行:
python PYDIR/scripts/runxlrd.py 3rows *blah*.xls
希望还可以翻阅 tutorial .
细节:
有关如何参与此包开发的细节及其它元信息,请参阅以下章节: