def parse_fonts(root, xmlns, color_index): """Read in the fonts""" font_list = [] fonts = root.find(QName(xmlns, 'fonts').text) if fonts is not None: font_nodes = fonts.findall(QName(xmlns, 'font').text) for font_node in font_nodes: font = Font() font.size = font_node.find(QName(xmlns, 'sz').text).get('val') font.name = font_node.find(QName(xmlns, 'name').text).get('val') font.bold = True if len(font_node.findall(QName( xmlns, 'b').text)) else False font.italic = True if len(font_node.findall( QName(xmlns, 'i').text)) else False if len(font_node.findall(QName(xmlns, 'u').text)): underline = font_node.find(QName(xmlns, 'u').text).get('val') font.underline = underline if underline else 'single' color = font_node.find(QName(xmlns, 'color').text) if color is not None: if color.get('indexed') is not None and 0 <= int( color.get('indexed')) < len(color_index): font.color.index = color_index[int(color.get('indexed'))] elif color.get('theme') is not None: if color.get('tint') is not None: font.color.index = 'theme:%s:%s' % (color.get('theme'), color.get('tint')) else: font.color.index = 'theme:%s:' % color.get( 'theme') # prefix color with theme elif color.get('rgb'): font.color.index = color.get('rgb') font_list.append(font) return font_list
def parse_fonts(root, color_index): """Read in the fonts""" font_list = [] fonts = root.find('{%s}fonts' % SHEET_MAIN_NS) if fonts is not None: font_nodes = fonts.findall('{%s}font' % SHEET_MAIN_NS) for font_node in font_nodes: font = Font() fontSizeEl = font_node.find('{%s}sz' % SHEET_MAIN_NS) if fontSizeEl is not None: font.size = fontSizeEl.get('val') fontNameEl = font_node.find('{%s}name' % SHEET_MAIN_NS) if fontNameEl is not None: font.name = fontNameEl.get('val') font.bold = True if len(font_node.findall('{%s}b' % SHEET_MAIN_NS)) else False font.italic = True if len(font_node.findall('{%s}i' % SHEET_MAIN_NS)) else False if len(font_node.findall('{%s}u' % SHEET_MAIN_NS)): underline = font_node.find('{%s}u' % SHEET_MAIN_NS).get('val') font.underline = underline if underline else 'single' color = font_node.find('{%s}color' % SHEET_MAIN_NS) if color is not None: if color.get('indexed') is not None and 0 <= int(color.get('indexed')) < len(color_index): font.color.index = color_index[int(color.get('indexed'))] elif color.get('theme') is not None: if color.get('tint') is not None: font.color.index = 'theme:%s:%s' % (color.get('theme'), color.get('tint')) else: font.color.index = 'theme:%s:' % color.get('theme') # prefix color with theme elif color.get('rgb'): font.color.index = color.get('rgb') font_list.append(font) return font_list
def parse_fonts(root, xmlns, color_index): """Read in the fonts""" font_list = [] fonts = root.find(QName(xmlns, 'fonts').text) if fonts is not None: font_nodes = fonts.findall(QName(xmlns, 'font').text) for font_node in font_nodes: font = Font() font.size = font_node.find(QName(xmlns, 'sz').text).get('val') font.name = font_node.find(QName(xmlns, 'name').text).get('val') font.bold = True if len(font_node.findall(QName(xmlns, 'b').text)) else False font.italic = True if len(font_node.findall(QName(xmlns, 'i').text)) else False if len(font_node.findall(QName(xmlns, 'u').text)): underline = font_node.find(QName(xmlns, 'u').text).get('val') font.underline = underline if underline else 'single' color = font_node.find(QName(xmlns, 'color').text) if color is not None: if color.get('indexed') is not None and 0 <= int(color.get('indexed')) < len(color_index): font.color.index = color_index[int(color.get('indexed'))] elif color.get('theme') is not None: if color.get('tint') is not None: font.color.index = 'theme:%s:%s' % (color.get('theme'), color.get('tint')) else: font.color.index = 'theme:%s:' % color.get('theme') # prefix color with theme elif color.get('rgb'): font.color.index = color.get('rgb') font_list.append(font) return font_list
def parse_fonts(root, color_index): """Read in the fonts""" font_list = [] fonts = root.find("{%s}fonts" % SHEET_MAIN_NS) if fonts is not None: font_nodes = fonts.findall("{%s}font" % SHEET_MAIN_NS) for font_node in font_nodes: font = Font() font.size = font_node.find("{%s}sz" % SHEET_MAIN_NS).get("val") font.name = font_node.find("{%s}name" % SHEET_MAIN_NS).get("val") font.bold = True if len(font_node.findall("{%s}b" % SHEET_MAIN_NS)) else False font.italic = True if len(font_node.findall("{%s}i" % SHEET_MAIN_NS)) else False if len(font_node.findall("{%s}u" % SHEET_MAIN_NS)): underline = font_node.find("{%s}u" % SHEET_MAIN_NS).get("val") font.underline = underline if underline else "single" color = font_node.find("{%s}color" % SHEET_MAIN_NS) if color is not None: if color.get("indexed") is not None and 0 <= int(color.get("indexed")) < len(color_index): font.color.index = color_index[int(color.get("indexed"))] elif color.get("theme") is not None: if color.get("tint") is not None: font.color.index = "theme:%s:%s" % (color.get("theme"), color.get("tint")) else: font.color.index = "theme:%s:" % color.get("theme") # prefix color with theme elif color.get("rgb"): font.color.index = color.get("rgb") font_list.append(font) return font_list
def parse_fonts(root, color_index): """Read in the fonts""" font_list = [] fonts = root.find('{%s}fonts' % SHEET_MAIN_NS) if fonts is not None: font_nodes = fonts.findall('{%s}font' % SHEET_MAIN_NS) for font_node in font_nodes: font = Font() fontSizeEl = font_node.find('{%s}sz' % SHEET_MAIN_NS) if fontSizeEl is not None: font.size = fontSizeEl.get('val') fontNameEl = font_node.find('{%s}name' % SHEET_MAIN_NS) if fontNameEl is not None: font.name = fontNameEl.get('val') font.bold = True if len(font_node.findall( '{%s}b' % SHEET_MAIN_NS)) else False font.italic = True if len( font_node.findall('{%s}i' % SHEET_MAIN_NS)) else False if len(font_node.findall('{%s}u' % SHEET_MAIN_NS)): underline = font_node.find('{%s}u' % SHEET_MAIN_NS).get('val') font.underline = underline if underline else 'single' color = font_node.find('{%s}color' % SHEET_MAIN_NS) if color is not None: if color.get('indexed') is not None and 0 <= int( color.get('indexed')) < len(color_index): font.color.index = color_index[int(color.get('indexed'))] elif color.get('theme') is not None: if color.get('tint') is not None: font.color.index = 'theme:%s:%s' % (color.get('theme'), color.get('tint')) else: font.color.index = 'theme:%s:' % color.get( 'theme') # prefix color with theme elif color.get('rgb'): font.color.index = color.get('rgb') font_list.append(font) return font_list