跳转到主要内容

开发人员从Microsoft Excel(tm).xls电子表格文件中提取数据的库

项目描述

Build Status Coverage Status Documentation PyPI version

xlrd是从历史格式.xls的Excel文件中读取数据和格式化信息的库。

以下内容也不受支持,但将安全可靠地被忽略

  • 图表、宏、图片、任何其他嵌入对象,包括嵌入的工作表。

  • 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

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面