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