Example #1
0
def write_root_rels(workbook):
    """Write the relationships xml."""

    rels = RelationshipList()

    rel = Relationship(type="officeDocument", target=ARC_WORKBOOK, id="rId1")
    rels.append(rel)

    rel = Relationship("", target=ARC_CORE, id='rId2',)
    rel.type = "%s/metadata/core-properties" % PKG_REL_NS
    rels.append(rel)

    rel = Relationship("extended-properties", target=ARC_APP, id='rId3')
    rels.append(rel)

    if workbook.vba_archive is not None:
        relation_tag = '{%s}Relationship' % PKG_REL_NS
        # See if there was a customUI relation and reuse its id
        arc = fromstring(workbook.vba_archive.read(ARC_ROOT_RELS))
        rel_tags = arc.findall(relation_tag)
        rId = None
        for rel in rel_tags:
                if rel.get('Target') == ARC_CUSTOM_UI:
                        rId = rel.get('Id')
                        break
        if rId is not None:
            vba = Relationship("", target=ARC_CUSTOM_UI, id=rId)
            vba.type = CUSTOMUI_NS
            rels.append(vba)

    return tostring(rels.to_tree())
Example #2
0
def write_root_rels(workbook):
    """Write the relationships xml."""
    root = Element("Relationships", xmlns=PKG_REL_NS)
    relation_tag = "{%s}Relationship" % PKG_REL_NS

    rel = Relationship(type="officeDocument", target=ARC_WORKBOOK, id="rId1")
    root.append(rel.to_tree())

    rel = Relationship("", target=ARC_CORE, id="rId2")
    rel.type = "%s/metadata/core-properties" % PKG_REL_NS
    root.append(rel.to_tree())

    rel = Relationship("extended-properties", target=ARC_APP, id="rId3")

    root.append(rel.to_tree())

    if workbook.vba_archive is not None:
        # See if there was a customUI relation and reuse its id
        arc = fromstring(workbook.vba_archive.read(ARC_ROOT_RELS))
        rels = arc.findall(relation_tag)
        rId = None
        for rel in rels:
            if rel.get("Target") == ARC_CUSTOM_UI:
                rId = rel.get("Id")
                break
        if rId is not None:
            vba = Relationship("", target=ARC_CUSTOM_UI, id=rId)
            vba.type = CUSTOMUI_NS
            root.append(vba.to_tree())

    return tostring(root)
Example #3
0
def write_external_book_rel(book):
    """Serialise link to external file"""
    root = Element("Relationships", xmlns=PKG_REL_NS)
    rel = Relationship("", target=book.Target, targetMode=book.TargetMode, id="rId1")
    rel.type = book.Type
    root.append(rel.to_tree())
    return root
Example #4
0
def write_workbook_rels(workbook):
    """Write the workbook relationships xml."""
    root = Element("Relationships", xmlns=PKG_REL_NS)

    for i, _ in enumerate(workbook.worksheets, 1):
        rel = Relationship(type="worksheet", target="worksheets/sheet%s.xml" % i, id="rId%d" % i)
        root.append(rel.to_tree())

    i += 1
    strings = Relationship(type="sharedStrings", target="sharedStrings.xml", id="rId%d" % i)
    root.append(strings.to_tree())

    i += 1
    styles = Relationship(type="styles", target="styles.xml", id="rId%d" % i)
    root.append(styles.to_tree())

    i += 1
    styles = Relationship(type="theme", target="theme/theme1.xml", id="rId%d" % i)
    root.append(styles.to_tree())

    if workbook.vba_archive:
        i += 1
        vba = Relationship(type="vbaProject", target="vbaProject.bin", id="rId%d" % i)
        vba.type = "http://schemas.microsoft.com/office/2006/relationships/vbaProject"
        root.append(vba.to_tree())

    external_links = workbook._external_links
    if external_links:
        for idx, link in enumerate(external_links, 1):
            ext = Relationship(
                type="externalLink", target="externalLinks/externalLink%d.xml" % idx, id="rId%d" % (i + idx)
            )
            root.append(ext.to_tree())

    return tostring(root)
def write_external_book_rel(book):
    """Serialise link to external file"""
    root = Element("Relationships", xmlns=PKG_REL_NS)
    rel = Relationship("",
                       target=book.Target,
                       targetMode=book.TargetMode,
                       id="rId1")
    rel.type = book.Type
    root.append(rel.to_tree())
    return root
Example #6
0
def write_workbook_rels(workbook):
    """Write the workbook relationships xml."""
    rels = RelationshipList()

    rId = 0

    for idx, _ in enumerate(workbook.worksheets, 1):
        rId += 1
        rel = Relationship(type='worksheet',
                           target='worksheets/sheet%s.xml' % idx,
                           id='rId%d' % rId)
        rels.append(rel)

    for idx, _ in enumerate(workbook.chartsheets, 1):
        rId += 1
        rel = Relationship(type='chartsheet',
                           target='chartsheets/sheet%s.xml' % idx,
                           id='rId%d' % rId)
        rels.append(rel)

    rId += 1
    strings = Relationship(type='sharedStrings',
                           target='sharedStrings.xml',
                           id='rId%d' % rId)
    rels.append(strings)

    rId += 1
    styles = Relationship(type='styles', target='styles.xml', id='rId%d' % rId)
    rels.append(styles)

    rId += 1
    theme = Relationship(type='theme',
                         target='theme/theme1.xml',
                         id='rId%d' % rId)
    rels.append(theme)

    if workbook.vba_archive:
        rId += 1
        vba = Relationship(type='vbaProject',
                           target='vbaProject.bin',
                           id='rId%d' % rId)
        vba.type = 'http://schemas.microsoft.com/office/2006/relationships/vbaProject'
        rels.append(vba)

    external_links = workbook._external_links
    if external_links:
        for idx, link in enumerate(external_links, 1):
            ext = Relationship(type='externalLink',
                               target='externalLinks/externalLink%d.xml' % idx,
                               id='rId%d' % (rId + idx))
            rels.append(ext)

    return tostring(rels.to_tree())
Example #7
0
def write_workbook_rels(workbook):
    """Write the workbook relationships xml."""
    rels = RelationshipList()

    rId = 0

    for idx, _ in enumerate(workbook.worksheets, 1):
        rId += 1
        rel = Relationship(type='worksheet', target='worksheets/sheet%s.xml' % idx, id='rId%d' % rId)
        rels.append(rel)


    for idx, _ in enumerate(workbook.chartsheets, 1):
        rId += 1
        rel = Relationship(type='chartsheet', target='chartsheets/sheet%s.xml' % idx, id='rId%d' % rId)
        rels.append(rel)

    rId += 1
    strings =  Relationship(type='sharedStrings', target='sharedStrings.xml', id='rId%d' % rId)
    rels.append(strings)

    rId += 1
    styles =  Relationship(type='styles', target='styles.xml', id='rId%d' % rId)
    rels.append(styles)

    rId += 1
    theme =  Relationship(type='theme', target='theme/theme1.xml', id='rId%d' % rId)
    rels.append(theme)

    if workbook.vba_archive:
        rId += 1
        vba =  Relationship(type='vbaProject', target='vbaProject.bin', id='rId%d' % rId)
        vba.type ='http://schemas.microsoft.com/office/2006/relationships/vbaProject'
        rels.append(vba)

    external_links = workbook._external_links
    if external_links:
        for idx, link in enumerate(external_links, 1):
            ext =  Relationship(type='externalLink',
                                target='externalLinks/externalLink%d.xml' % idx,
                                id='rId%d' % (rId +idx))
            rels.append(ext)

    return tostring(rels.to_tree())
Example #8
0
def write_workbook_rels(workbook):
    """Write the workbook relationships xml."""
    root = Element('Relationships', xmlns=PKG_REL_NS)

    for i, _ in enumerate(workbook.worksheets, 1):
        rel = Relationship(type='worksheet',
                           target='worksheets/sheet%s.xml' % i,
                           id='rId%d' % i)
        root.append(rel.to_tree())

    i += 1
    strings = Relationship(type='sharedStrings',
                           target='sharedStrings.xml',
                           id='rId%d' % i)
    root.append(strings.to_tree())

    i += 1
    styles = Relationship(type='styles', target='styles.xml', id='rId%d' % i)
    root.append(styles.to_tree())

    i += 1
    styles = Relationship(type='theme',
                          target='theme/theme1.xml',
                          id='rId%d' % i)
    root.append(styles.to_tree())

    if workbook.vba_archive:
        i += 1
        vba = Relationship(type='vbaProject',
                           target='vbaProject.bin',
                           id='rId%d' % i)
        vba.type = 'http://schemas.microsoft.com/office/2006/relationships/vbaProject'
        root.append(vba.to_tree())

    external_links = workbook._external_links
    if external_links:
        for idx, link in enumerate(external_links, 1):
            ext = Relationship(type='externalLink',
                               target='externalLinks/externalLink%d.xml' % idx,
                               id='rId%d' % (i + idx))
            root.append(ext.to_tree())

    return tostring(root)