栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Python中获取Excel单元格属性

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Python中获取Excel单元格属性

以下内容使用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)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624558.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号