小编ana*_*nth的帖子

如何使用 xlrd 版本 1.1.0 读取 Excel 中的字体和背景颜色

实际上我使用的是xlrd模块1.1.0版本,但我不知道如何读取单元格属性,如背景颜色、字体以及单元格是否被锁定。

我尝试使用

import xlrd
book = xlrd.open_workbook("sample.xls", formatting_info=True)
sheets = book.sheet_names()
print "sheets are:", sheets
for index, sh in enumerate(sheets):
    sheet = book.sheet_by_index(index)
    print "Sheet:", sheet.name
    rows, cols = sheet.nrows, sheet.ncols
    print "Number of rows: %s   Number of cols: %s" % (rows, cols)
    for row in range(rows):
        for col in range(cols):
            print "row, col is:", row+1, col+1,
            thecell = sheet.cell(row, col)      
            # could get 'dump', 'value', 'xf_index'
            print thecell.value,
            xfx = sheet.cell_`enter code here`xf_index(row, col)
            xf = book.xf_list[xfx]
            bgx = …
Run Code Online (Sandbox Code Playgroud)

python xlrd

4
推荐指数
1
解决办法
5357
查看次数

标签 统计

python ×1

xlrd ×1