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


Python DocxBuilder.numbering方法代码示例

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


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

示例1: load_document

# 需要导入模块: from pydocx.test.document_builder import DocxBuilder [as 别名]
# 或者: from pydocx.test.document_builder.DocxBuilder import numbering [as 别名]
    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,代码行数:58,代码来源:utils.py

示例2: _load

# 需要导入模块: from pydocx.test.document_builder import DocxBuilder [as 别名]
# 或者: from pydocx.test.document_builder.DocxBuilder import numbering [as 别名]
    def _load(self):
        self.document = WordprocessingDocument(path=None)
        package = self.document.package
        document_part = package.create_part(
            uri='/word/document.xml',
        )

        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,
        )

        self.numbering_root = None
        if self.numbering_dict is not None:
            data = DXB.numbering(self.numbering_dict)
            self.numbering_root = parse_xml_from_string(
                xml=data,
                remove_namespaces=True,
            )

        # 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

        self.styles_manager = StylesManager(
            self.document.main_document_part.style_definitions_part,
        )
        self.styles = self.styles_manager.styles

        self.parse_begin(self.document.main_document_part)
开发者ID:OmniaSolutions,项目名称:pydocx,代码行数:65,代码来源:utils.py


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