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


Python document_builder.DocxBuilder类代码示例

本文整理汇总了Python中pydocx.test.document_builder.DocxBuilder的典型用法代码示例。如果您正苦于以下问题:Python DocxBuilder类的具体用法?Python DocxBuilder怎么用?Python DocxBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: get_xml

    def get_xml(self):
        li_text = [
            ('AAA', 0, 1),
            ('BBB', 1, 1),
            ('CCC', 2, 1),
            ('DDD', 2, 1),
            ('EEE', 1, 1),
            ('FFF', 2, 1),
            ('GGG', 2, 1),
            ('HHH', 1, 1),
            ('III', 2, 1),
            ('JJJ', 2, 1),
            ('KKK', 0, 1),
            ('LLL', 0, 2),
            ('MMM', 1, 2),
            ('NNN', 1, 2),
            ('OOO', 0, 2),
            ('PPP', 1, 2),
            ('QQQ', 1, 2),
            ('RRR', 2, 2),
            ('SSS', 0, 2),
            ('TTT', 1, 2),
            ('UUU', 1, 2),
        ]
        lis = b''
        for text, ilvl, numId in li_text:
            lis += DXB.li(text=text, ilvl=ilvl, numId=numId)

        xml = DXB.xml(lis)
        return xml
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:30,代码来源:test_xml.py

示例2: get_xml

    def get_xml(self):
        li_text = [
            ('AAA', 0, 2),
            # Because AAA and CCC are part of the same list (same list id)
            # and BBB is different, these need to be split into three
            # lists (or lose everything from BBB and after.
            ('BBB', 0, 1),
            ('CCC', 0, 2),
        ]
        lis = b''
        for text, ilvl, numId in li_text:
            lis += DXB.li(text=text, ilvl=ilvl, numId=numId)

        xml = DXB.xml(lis)
        return xml
开发者ID:OmniaSolutions,项目名称:pydocx,代码行数:15,代码来源:test_xml.py

示例3: get_xml

    def get_xml(self):
        tags = [
            DXB.li(text='AAA', ilvl=0, numId=2),
            # Because AAA and DDD are part of the same list (same list id)
            # and BBB,CCC are different, these need to be properly formatted
            # into a single list where BBB,CCC are added as nested list to AAA item
            DXB.li(text='BBB', ilvl=0, numId=1),
            DXB.li(text='CCC', ilvl=0, numId=1),
            DXB.li(text='DDD', ilvl=0, numId=2),
        ]
        body = b''
        for el in tags:
            body += el

        xml = DXB.xml(body)
        return xml
开发者ID:CenterForOpenScience,项目名称:pydocx,代码行数:16,代码来源:test_xml.py

示例4: load_document

    def load_document(self):
        # It's likely that we could replace this logic with a
        # WordprocessingDocumentFactory
        document = WordprocessingDocument(path=None)
        package = document.package
        document_part = package.create_part(uri="/word/document.xml")

        if self.numbering_dict is not None:
            numbering_xml = DXB.numbering(self.numbering_dict)
            self.relationships.append(
                {
                    "external": False,
                    "target_path": "numbering.xml",
                    "data": numbering_xml,
                    "relationship_id": "numbering",
                    "relationship_type": NumberingDefinitionsPart.relationship_type,  # noqa
                }
            )

        if self.styles_xml:
            self.relationships.append(
                {
                    "external": False,
                    "target_path": "styles.xml",
                    "data": self.styles_xml,
                    "relationship_id": "styles",
                    "relationship_type": StyleDefinitionsPart.relationship_type,
                }
            )

        for relationship in self.relationships:
            target_mode = "Internal"
            if relationship["external"]:
                target_mode = "External"
            target_uri = relationship["target_path"]
            if "data" in relationship:
                full_target_uri = posixpath.join(package.uri, "word", target_uri)
                package.streams[full_target_uri] = BytesIO(relationship["data"])
                package.create_part(uri=full_target_uri)
            document_part.create_relationship(
                target_uri=target_uri,
                target_mode=target_mode,
                relationship_type=relationship["relationship_type"],
                relationship_id=relationship["relationship_id"],
            )

        package.streams[document_part.uri] = BytesIO(self.document_xml)
        package.create_relationship(
            target_uri=document_part.uri, target_mode="Internal", relationship_type=MainDocumentPart.relationship_type
        )

        # This is the standard page width for a word document (in points), Also
        # the page width that we are looking for in the test.
        self._page_width = 612

        return document
开发者ID:botzill,项目名称:pydocx,代码行数:56,代码来源:utils.py


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