本文整理汇总了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
示例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)