当前位置: 首页>>代码示例>>Python>>正文


Python Element.findall方法代码示例

本文整理汇总了Python中openpyxl.xml.functions.Element.findall方法的典型用法代码示例。如果您正苦于以下问题:Python Element.findall方法的具体用法?Python Element.findall怎么用?Python Element.findall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openpyxl.xml.functions.Element的用法示例。


在下文中一共展示了Element.findall方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write

# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import findall [as 别名]
    def write(self, root):
        # Remove any existing comment shapes
        if not hasattr(root, "findall"):
            root = Element("xml")

        comments = root.findall("{%s}shape" % vmlns)
        for c in comments:
            if c.get("type") == '#_x0000_t202':
                root.remove(c)

        # check whether comments shape type already exists
        shape_types = root.findall("{%s}shapetype" % vmlns)
        comments_type = False
        for s in shape_types:
            if s.get("id") == '_x0000_t202':
                comments_type = True
                break

        if not comments_type:
            self.add_comment_shapetype(root)

        for idx, (coord, comment) in enumerate(self.comments, 1026):
            self.add_comment_shape(root, idx, coord)

        return tostring(root)
开发者ID:olivx,项目名称:scripts,代码行数:27,代码来源:shape_writer.py

示例2: write

# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import findall [as 别名]
    def write(self, root):

        if not hasattr(root, "findall"):
            root = Element("xml")

        # Remove any existing comment shapes
        comments = root.findall("{%s}shape[@type='#_x0000_t202']" % vmlns)
        for c in comments:
            root.remove(c)

        # check whether comments shape type already exists
        shape_types = root.find("{%s}shapetype[@id='_x0000_t202']" % vmlns)
        if not shape_types:
            self.add_comment_shapetype(root)

        for idx, (coord, comment) in enumerate(self.comments, 1026):
            self.add_comment_shape(root, idx, coord, comment.height, comment.width)

        return tostring(root)
开发者ID:JLL-Benson,项目名称:CHN_DQ,代码行数:21,代码来源:shape_writer.py

示例3: write_content_types

# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import findall [as 别名]
def write_content_types(workbook, as_template=False):
    """Write the content-types xml."""

    seen = set()
    if workbook.vba_archive:
        root = fromstring(workbook.vba_archive.read(ARC_CONTENT_TYPES))
        for elem in root.findall('{%s}Override' % CONTYPES_NS):
            seen.add(elem.attrib['PartName'])
        for elem in root.findall('{%s}Default' % CONTYPES_NS):
            seen.add(elem.attrib['Extension'])
    else:
        if LXML:
            NSMAP = {None : CONTYPES_NS}
            root = Element('{%s}Types' % CONTYPES_NS, nsmap=NSMAP)
        else:
            root = Element('{%s}Types' % CONTYPES_NS)

    for setting_type, name, content_type in static_content_types_config:

        attrib = {'ContentType': content_type}
        if setting_type == 'Override':
            if '/' + name not in seen:
                tag = '{%s}Override' % CONTYPES_NS
                attrib['PartName'] = '/' + name
                SubElement(root, tag, attrib)
        else:
            if name not in seen:
                tag = '{%s}Default' % CONTYPES_NS
                attrib['Extension'] = name
                SubElement(root, tag, attrib)

    nodes = root.findall('{%s}Override' % CONTYPES_NS)
    for wb_elem in nodes:
        if wb_elem.get("PartName") == "/" + ARC_WORKBOOK:
            ct = as_template and XLTX or XLSX
            if workbook.vba_archive:
                ct = as_template and XLTM or XLSM
            wb_elem.set("ContentType", ct)

    drawing_id = 1
    chart_id = 1
    comments_id = 1

    for sheet_id, sheet in enumerate(workbook.worksheets):
        name = '/xl/worksheets/sheet%d.xml' % (sheet_id + 1)
        if name not in seen:
            SubElement(root, '{%s}Override' % CONTYPES_NS, {
                'PartName': name,
                'ContentType': WORKSHEET_TYPE
            })

        if sheet._charts or sheet._images:
            name = '/xl/drawings/drawing%d.xml' % drawing_id
            if name not in seen:
                SubElement(root, '{%s}Override' % CONTYPES_NS, {
                    'PartName': name,
                    'ContentType': DRAWING_TYPE
                })

            drawing_id += 1

            for chart in sheet._charts:
                name = '/xl/charts/chart%d.xml' % chart_id
                if name not in seen:
                    SubElement(root, '{%s}Override' % CONTYPES_NS, {
                        'PartName': name,
                        'ContentType': CHART_TYPE
                    })

                chart_id += 1

                if chart._shapes:
                    name = '/xl/drawings/drawing%d.xml' % drawing_id
                    if name not in seen:
                        SubElement(root, '{%s}Override' % CONTYPES_NS, {
                            'PartName': name,
                            'ContentType': CHARTSHAPE_TYPE
                        })

                    drawing_id += 1

        if sheet._comment_count > 0:
            name = '/xl/comments%d.xml' % comments_id
            if name not in seen:
                SubElement(root, '{%s}Override' % CONTYPES_NS, {
                    'PartName': name,
                    'ContentType': COMMENTS_TYPE
                })
            comments_id += 1

    for idx, _ in enumerate(workbook._external_links, 1):
        el = Element('{%s}Override' % CONTYPES_NS, {
            'PartName': '/xl/externalLinks/externalLink{0}.xml'.format(idx),
            'ContentType': EXTERNAL_LINK
        })
        root.append(el)

    return tostring(root)
开发者ID:indoorvoice,项目名称:WiFinder,代码行数:100,代码来源:workbook.py


注:本文中的openpyxl.xml.functions.Element.findall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。