关于python xlrd的问题

4 投票
2 回答
9241 浏览
提问于 2025-04-16 01:41

如何知道在下面这个链接中的Excel表格里总共用了多少列:

http://scienceoss.com/read-excel-files-from-python/

谢谢。

2 个回答

8

以下是xlrd的README.html中“快速开始”部分的前六行:

import xlrd
book = xlrd.open_workbook("myfile.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols

你可以通过这个链接获取教程。同样,文档的最新版本也可以在SVN上找到。如果你是通过源代码包安装xlrd或者使用Windows安装程序安装的,那么你应该已经有这些文档了。

8

Sheet类里面有一个叫ncols的成员,它表示这个表格有多少列。

撰写回答