本文整理汇总了Python中openpyxl.xml.functions.Element.set方法的典型用法代码示例。如果您正苦于以下问题:Python Element.set方法的具体用法?Python Element.set怎么用?Python Element.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.xml.functions.Element
的用法示例。
在下文中一共展示了Element.set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import set [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
示例2: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import set [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
示例3: append
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import set [as 别名]
def append(self, row):
"""
:param row: iterable containing values to append
:type row: iterable
"""
if (not isgenerator(row) and
not isinstance(row, (list, tuple, range))
):
self._invalid_row(row)
cell = WriteOnlyCell(self) # singleton
self._max_row += 1
row_idx = self._max_row
if self.writer is None:
self.writer = self._write_header()
next(self.writer)
el = Element("row", r='%d' % self._max_row)
col_idx = None
for col_idx, value in enumerate(row, 1):
if value is None:
continue
try:
cell.value = value
except ValueError:
if isinstance(value, Cell):
cell = value
if cell.comment is not None:
comment = cell.comment
comment._parent = CommentParentCell(cell)
self._comments.append(comment)
else:
raise ValueError
cell.col_idx = col_idx
cell.row = row_idx
styled = cell.has_style
tree = write_cell(self, cell, styled)
el.append(tree)
if styled: # styled cell or datetime
cell = WriteOnlyCell(self)
if col_idx:
self._max_col = max(self._max_col, col_idx)
el.set('spans', '1:%d' % col_idx)
try:
self.writer.send(el)
except StopIteration:
self._already_saved()
示例4: write_string_table
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import set [as 别名]
def write_string_table(string_table):
"""Write the string table xml."""
out = BytesIO()
with xmlfile(out) as xf:
with xf.element("sst", xmlns=SHEET_MAIN_NS, uniqueCount="%d" % len(string_table)):
for key in string_table:
el = Element('si')
if key.strip() != key:
el.set(PRESERVE_SPACE, 'preserve')
text = SubElement(el, 't')
text.text = key
xf.write(el)
return out.getvalue()
示例5: append
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import set [as 别名]
def append(self, row):
"""
:param row: iterable containing values to append
:type row: iterable
"""
if not isgenerator(row) and not isinstance(row, (list, tuple, range)):
self._invalid_row(row)
cell = WriteOnlyCell(self) # singleton
self._max_row += 1
row_idx = self._max_row
if self.writer is None:
self.writer = self._write_header()
next(self.writer)
el = Element("row", r="%d" % self._max_row)
col_idx = None
for col_idx, value in enumerate(row, 1):
if value is None:
continue
column = get_column_letter(col_idx)
if isinstance(value, Cell):
cell = value
else:
cell.value = value
cell.coordinate = "%s%d" % (column, row_idx)
if cell.comment is not None:
comment = cell.comment
comment._parent = CommentParentCell(cell)
self._comments.append(comment)
tree = write_cell(self, cell)
el.append(tree)
if cell.has_style: # styled cell or datetime
cell = WriteOnlyCell(self)
if col_idx:
self._max_col = max(self._max_col, col_idx)
el.set("spans", "1:%d" % col_idx)
try:
self.writer.send(el)
except StopIteration:
self._already_saved()
示例6: write_cols
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import set [as 别名]
def write_cols(worksheet):
"""Write worksheet columns to xml.
<cols> may never be empty -
spec says must contain at least one child
"""
def sorter(value):
return column_index_from_string(value[0])
el = Element('cols')
obj = None
for idx, col in sorted(worksheet.column_dimensions.items(), key=sorter):
if dict(col) == {}:
continue
idx = column_index_from_string(idx)
obj = Element('col', dict(col))
obj.set('min', '%d' % (col.min or idx))
obj.set('max', '%d' % (col.max or idx))
el.append(obj)
if obj is not None:
return el