以下内容使用xlrd 0.7.6版对我有效:
from xlrd import open_workbookwb = open_workbook('tmp.xls', formatting_info=True)sheet = wb.sheet_by_name("1")cell = sheet.cell(6, 0)print "cell.xf_index is", cell.xf_indexfmt = wb.xf_list[cell.xf_index]print "type(fmt) is", type(fmt)printprint "fmt.dump():"fmt.dump()fmt是XF类的实例;参见https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html#formatting.XF-
class
该
dump()方法打印有关格式的所有信息。这是上面代码的输出:
cell.xf_index is 497type(fmt) is <class 'xlrd.formatting.XF'>fmt.dump():_alignment_flag: 1_background_flag: 1_border_flag: 1_font_flag: 1_format_flag: 0_protection_flag: 0alignment (XFAlignment object): hor_align: 1 indent_level: 0 rotation: 0 shrink_to_fit: 0 text_direction: 0 text_wrapped: 0 vert_align: 2background (XFBackground object): background_colour_index: 64 fill_pattern: 1 pattern_colour_index: 17border (XFBorder object): bottom_colour_index: 0 bottom_line_style: 0 diag_colour_index: 0 diag_down: 0 diag_line_style: 0 diag_up: 0 left_colour_index: 0 left_line_style: 0 right_colour_index: 0 right_line_style: 0 top_colour_index: 56 top_line_style: 1font_index: 72format_key: 0is_style: 0lotus_123_prefix: 0parent_style_index: 0protection (XFProtection object): cell_locked: 1 formula_hidden: 0xf_index: 497
其中一些值是工作簿列表中的索引
wb。例如,
fmt.font_index为72,并且
wb.font_list[72]是
Font该类的实例(https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html#formatting.Font-class)。



