本文整理汇总了Python中openpyxl.xml.functions.Element.append方法的典型用法代码示例。如果您正苦于以下问题:Python Element.append方法的具体用法?Python Element.append怎么用?Python Element.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.xml.functions.Element
的用法示例。
在下文中一共展示了Element.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_comments_vml
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_comments_vml(self):
root = Element("xml")
shape_layout = SubElement(root, "{%s}shapelayout" % officens,
{"{%s}ext" % vmlns: "edit"})
SubElement(shape_layout,
"{%s}idmap" % officens,
{"{%s}ext" % vmlns: "edit", "data": "1"})
shape_type = SubElement(root,
"{%s}shapetype" % vmlns,
{"id": "_x0000_t202",
"coordsize": "21600,21600",
"{%s}spt" % officens: "202",
"path": "m,l,21600r21600,l21600,xe"})
SubElement(shape_type, "{%s}stroke" % vmlns, {"joinstyle": "miter"})
SubElement(shape_type,
"{%s}path" % vmlns,
{"gradientshapeok": "t",
"{%s}connecttype" % officens: "rect"})
for idx, comment in enumerate(self.comments, 1026):
shape = _shape_factory()
col, row = coordinate_from_string(comment.ref)
row -= 1
column = column_index_from_string(col) - 1
shape.set('id', "_x0000_s%04d" % idx)
client_data = shape.find("{%s}ClientData" % excelns)
client_data.find("{%s}Row" % excelns).text = str(row)
client_data.find("{%s}Column" % excelns).text = str(column)
root.append(shape)
return tostring(root)
示例2: write_external_book_rel
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
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
示例3: write_rels
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_rels(worksheet, comments_id=None, vba_controls_id=None):
"""Write relationships for the worksheet to xml."""
root = Element('Relationships', xmlns=PKG_REL_NS)
rels = worksheet._rels
# VBA
if worksheet.vba_controls is not None:
rel = Relationship("vmlDrawing", id=worksheet.vba_controls,
target='/xl/drawings/vmlDrawing%s.vml' % vba_controls_id)
rels.append(rel)
# Comments
if worksheet._comment_count > 0:
rel = Relationship(type="comments", id="comments",
target='/xl/comments%s.xml' % comments_id)
rels.append(rel)
if worksheet.vba_controls is None:
rel = Relationship(type="vmlDrawing", id="commentsvml",
target='/xl/drawings/commentsDrawing%s.vml' % comments_id)
rels.append(rel)
for idx, rel in enumerate(rels, 1):
if rel.id is None:
rel.id = "rId{0}".format(idx)
root.append(rel.to_tree())
return root
示例4: write_external_book_rel
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_external_book_rel(book):
"""Serialise link to external file"""
root = Element("{%s}Relationships" % PKG_REL_NS)
attrs = {"Id":"rId1", "Target":book.Target, "TargetMode":book.TargetMode,
"Type":book.Type}
root.append(RelationElement(attrs))
return root
示例5: _write_header
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def _write_header(self):
"""
Generator that creates the XML file and the sheet header
"""
with xmlfile(self.filename) as xf:
with xf.element("worksheet", xmlns=SHEET_MAIN_NS):
if self.sheet_properties:
pr = write_sheetPr(self.sheet_properties)
xf.write(pr)
views = Element("sheetViews")
views.append(self.sheet_view.to_tree())
xf.write(views)
xf.write(write_format(self))
cols = write_cols(self)
if cols is not None:
xf.write(cols)
with xf.element("sheetData"):
try:
while True:
r = (yield)
xf.write(r)
except GeneratorExit:
pass
af = write_autofilter(self)
if af is not None:
xf.write(af)
if self._comments:
comments = Element("legacyDrawing", {"{%s}id" % REL_NS: "commentsvml"})
xf.write(comments)
示例6: write_cols
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_cols(worksheet):
"""Write worksheet columns to xml.
<cols> may never be empty -
spec says must contain at least one child
"""
cols = []
for label, dimension in iteritems(worksheet.column_dimensions):
col_def = dict(dimension)
if col_def == {}:
continue
idx = column_index_from_string(label)
cols.append((idx, col_def))
if not cols:
return
el = Element('cols')
for idx, col_def in sorted(cols):
v = "%d" % idx
cmin = col_def.get('min') or v
cmax = col_def.get('max') or v
col_def.update({'min': cmin, 'max': cmax})
el.append(Element('col', col_def))
return el
示例7: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def to_tree(self, tagname, obj, namespace=None):
tagname = namespaced(self, tagname, namespace)
container = Element(tagname)
if self.count:
container.set('count', str(len(obj)))
for v in obj:
container.append(v.to_tree())
return container
示例8: _serialise_nested
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def _serialise_nested(self, sequence):
"""
Colors need special handling
"""
for idx, color in enumerate(sequence):
stop = Element("stop", position=str(idx))
stop.append(color.to_tree())
yield stop
示例9: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def to_tree(self):
tree = Element("Relationships", xmlns=PKG_REL_NS)
for idx, rel in enumerate(self.Relationship, 1):
if not rel.Id:
rel.Id = "rId{0}".format(idx)
tree.append(rel.to_tree())
return tree
示例10: write_pagebreaks
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_pagebreaks(worksheet):
breaks = worksheet.page_breaks
if breaks:
tag = Element('rowBreaks', {'count': str(len(breaks)),
'manualBreakCount': str(len(breaks))})
for b in breaks:
tag.append(Element('brk', id=str(b), man="true", max='16383',
min='0'))
return tag
示例11: write_properties
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_properties(worksheet, vba_attrs):
pr = Element('sheetPr', vba_attrs)
summary = Element('outlinePr',
summaryBelow='%d' % worksheet.show_summary_below,
summaryRight= '%d' % worksheet.show_summary_right)
pr.append(summary)
if worksheet.page_setup.fitToPage:
pr.append(Element('pageSetUpPr', fitToPage='1'))
return pr
示例12: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def to_tree(self, tagname=None):
parent = Element("fill")
el = Element(self.tagname, patternType=safe_string(self.patternType))
for c in self.__elements__:
value = getattr(self, c)
if value != Color():
el.append(value.to_tree(c))
parent.append(el)
return parent
示例13: write_mergecells
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_mergecells(worksheet):
"""Write merged cells to xml."""
cells = worksheet._merged_cells
if not cells:
return
merge = Element('mergeCells', count='%d' % len(cells))
for range_string in cells:
merge.append(Element('mergeCell', ref=range_string))
return merge
示例14: write_hyperlinks
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def write_hyperlinks(worksheet):
"""Write worksheet hyperlinks to xml."""
tag = Element('hyperlinks')
for cell in worksheet.get_cell_collection():
if cell.hyperlink_rel_id is not None:
attrs = {'display': cell.hyperlink,
'ref': cell.coordinate,
'{%s}id' % REL_NS: cell.hyperlink_rel_id}
tag.append(Element('hyperlink', attrs))
if tag.getchildren():
return tag
示例15: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import append [as 别名]
def to_tree(self, tagname=None):
parent = Element("fill")
el = Element(self.tagname)
if self.patternType is not None:
el.set('patternType', self.patternType)
for c in self.__elements__:
value = getattr(self, c)
if value != Color():
el.append(value.to_tree(c))
parent.append(el)
return parent