本文整理汇总了Python中openpyxl.utils.indexed_list.IndexedList.append方法的典型用法代码示例。如果您正苦于以下问题:Python IndexedList.append方法的具体用法?Python IndexedList.append怎么用?Python IndexedList.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.utils.indexed_list.IndexedList
的用法示例。
在下文中一共展示了IndexedList.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SharedStylesParser
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import append [as 别名]
class SharedStylesParser(object):
def __init__(self, xml_source):
self.root = fromstring(xml_source)
self.cell_styles = IndexedList()
self.differential_styles = []
self.color_index = COLOR_INDEX
self.font_list = IndexedList()
self.fill_list = IndexedList()
self.border_list = IndexedList()
self.alignments = IndexedList([Alignment()])
self.protections = IndexedList([Protection()])
self.custom_number_formats = {}
self.number_formats = IndexedList()
def parse(self):
self.parse_custom_num_formats()
self.parse_color_index()
self.font_list = IndexedList(self.parse_fonts())
self.fill_list = IndexedList(self.parse_fills())
self.border_list = IndexedList(self.parse_borders())
self.parse_dxfs()
self.parse_cell_styles()
self.parse_named_styles()
def parse_custom_num_formats(self):
"""Read in custom numeric formatting rules from the shared style table"""
custom_formats = {}
num_fmts = self.root.findall('{%s}numFmts/{%s}numFmt' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for node in num_fmts:
idx = int(node.get('numFmtId'))
self.custom_number_formats[idx] = node.get('formatCode')
self.number_formats.append(node.get('formatCode'))
def parse_color_index(self):
"""Read in the list of indexed colors"""
colors =\
self.root.findall('{%s}colors/{%s}indexedColors/{%s}rgbColor' %
(SHEET_MAIN_NS, SHEET_MAIN_NS, SHEET_MAIN_NS))
if not colors:
return
self.color_index = IndexedList([node.get('rgb') for node in colors])
def parse_dxfs(self):
"""Read in the dxfs effects - used by conditional formatting."""
for node in self.root.findall("{%s}dxfs/{%s}dxf" % (SHEET_MAIN_NS, SHEET_MAIN_NS) ):
self.differential_styles.append(DifferentialStyle.from_tree(node))
def parse_fonts(self):
"""Read in the fonts"""
fonts = self.root.findall('{%s}fonts/{%s}font' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for node in fonts:
yield Font.from_tree(node)
def parse_fills(self):
"""Read in the list of fills"""
fills = self.root.findall('{%s}fills/{%s}fill' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for fill in fills:
yield Fill.from_tree(fill)
def parse_borders(self):
"""Read in the boarders"""
borders = self.root.findall('{%s}borders/{%s}border' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for border_node in borders:
yield Border.from_tree(border_node)
def parse_named_styles(self):
"""
Extract named styles
"""
node = self.root.find("{%s}cellStyleXfs" % SHEET_MAIN_NS)
styles = self._parse_xfs(node)
names = self._parse_style_names()
for style in names.values():
_id = styles[style.xfId]
style.border = self.border_list[_id.borderId]
style.fill = self.fill_list[_id.fillId]
style.font = self.font_list[_id.fontId]
if _id.alignmentId:
style.alignment = self.alignments[_id.alignmentId]
if _id.protectionId:
style.protection = self.protections[_id.protectionId]
self.named_styles = names
def _parse_style_names(self):
"""
Extract style names. There can be duplicates in which case last wins
"""
node = self.root.find("{%s}cellStyles" % SHEET_MAIN_NS)
names = {}
for _name in safe_iterator(node, '{%s}cellStyle' % SHEET_MAIN_NS):
name = _name.get("name")
#.........这里部分代码省略.........
示例2: SharedStylesParser
# 需要导入模块: from openpyxl.utils.indexed_list import IndexedList [as 别名]
# 或者: from openpyxl.utils.indexed_list.IndexedList import append [as 别名]
class SharedStylesParser(object):
def __init__(self, xml_source):
self.root = fromstring(xml_source)
self.shared_styles = []
self.cell_styles = IndexedList()
self.cond_styles = []
self.style_prop = {}
self.color_index = COLOR_INDEX
self.font_list = IndexedList()
self.fill_list = IndexedList()
self.border_list = IndexedList()
self.alignments = IndexedList([Alignment()])
self.protections = IndexedList([Protection()])
self.number_formats = IndexedList()
def parse(self):
self.parse_custom_num_formats()
self.parse_color_index()
self.style_prop['color_index'] = self.color_index
self.font_list = IndexedList(self.parse_fonts())
self.fill_list = IndexedList(self.parse_fills())
self.border_list = IndexedList(self.parse_borders())
self.parse_dxfs()
self.parse_cell_styles()
def parse_custom_num_formats(self):
"""Read in custom numeric formatting rules from the shared style table"""
custom_formats = {}
num_fmts = self.root.findall('{%s}numFmts/{%s}numFmt' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for num_fmt_node in num_fmts:
fmt_code = num_fmt_node.get('formatCode').lower()
self.number_formats.append(fmt_code)
def parse_color_index(self):
"""Read in the list of indexed colors"""
colors =\
self.root.findall('{%s}colors/{%s}indexedColors/{%s}rgbColor' %
(SHEET_MAIN_NS, SHEET_MAIN_NS, SHEET_MAIN_NS))
if not colors:
return
self.color_index = IndexedList([node.get('rgb') for node in colors])
def parse_dxfs(self):
"""Read in the dxfs effects - used by conditional formatting."""
for node in self.root.findall("{%s}dxfs/{%s}dxf" % (SHEET_MAIN_NS, SHEET_MAIN_NS) ):
self.cond_styles.append(DifferentialStyle.from_tree(node))
def parse_fonts(self):
"""Read in the fonts"""
fonts = self.root.findall('{%s}fonts/{%s}font' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for node in fonts:
yield Font.from_tree(node)
def parse_fills(self):
"""Read in the list of fills"""
fills = self.root.findall('{%s}fills/{%s}fill' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for fill in fills:
yield Fill.from_tree(fill)
def parse_borders(self):
"""Read in the boarders"""
borders = self.root.findall('{%s}borders/{%s}border' % (SHEET_MAIN_NS, SHEET_MAIN_NS))
for border_node in borders:
yield Border.from_tree(border_node)
def parse_named_styles(self):
"""
Extract named styles
"""
ns = []
styles_node = self.root.find("{%s}cellStyleXfs" % SHEET_MAIN_NS)
self._parse_xfs(styles_node)
_ids = self.cell_styles
for _name, idx in self._parse_style_names():
_id = _ids[idx]
style = NamedStyle(name=_name)
style.border = self.border_list[_id.border]
style.fill = self.fill_list[_id.fill]
style.font = self.font_list[_id.font]
if _id.alignment:
style.alignment = self.alignments[_id.alignment]
if _id.protection:
style.protection = self.protections[_id.protection]
ns.append(style)
self.named_styles = IndexedList(ns)
def _parse_style_names(self):
names_node = self.root.find("{%s}cellStyles" % SHEET_MAIN_NS)
for _name in names_node:
yield _name.get("name"), int(_name.get("xfId"))
#.........这里部分代码省略.........