本文整理汇总了Python中openpyxl.xml.functions.Element.text方法的典型用法代码示例。如果您正苦于以下问题:Python Element.text方法的具体用法?Python Element.text怎么用?Python Element.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.xml.functions.Element
的用法示例。
在下文中一共展示了Element.text方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def to_tree(self, tagname):
"""
Return as XML node
"""
el = Element(tagname)
el.text = str(self)
return el
示例2: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def to_tree(self, tagname=None, value=None, namespace=None):
namespace = getattr(self, "namespace", namespace)
if value is not None:
if namespace is not None:
tagname = "{%s}%s" % (namespace, tagname)
el = Element(tagname)
el.text = safe_string(value)
return el
示例3: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def to_tree(self, tagname=None, value=None, namespace=None):
namespace = getattr(self, "namespace", namespace)
if namespace is not None:
tagname = "{%s}%s" % (namespace, tagname)
el = Element(tagname)
if value is not None:
el.text = datetime_to_W3CDTF(value)
return el
示例4: _write_defined_names
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def _write_defined_names(workbook, names):
"""
Append definedName elements to the definedNames node.
"""
for named_range in workbook.get_named_ranges():
attrs = dict(named_range)
if named_range.scope is not None:
attrs['localSheetId'] = safe_string(named_range.scope)
name = Element('{%s}definedName' % SHEET_MAIN_NS, attrs)
name.text = named_range.value
names.append(name)
示例5: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def to_tree(self, tagname, obj, namespace=None):
"""
Convert the sequence represented by the descriptor to an XML element
"""
for idx, v in enumerate(obj, self.idx_base):
if hasattr(v, "to_tree"):
el = v.to_tree(tagname, idx)
else:
tagname = namespaced(obj, tagname, namespace)
el = Element(tagname)
el.text = safe_string(v)
yield el
示例6: writer
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def writer(data_validation):
"""
Serialse a data validation
"""
attrs = dict(data_validation)
el = Element("{%s}dataValidation" % SHEET_MAIN_NS, attrs)
for attr in ("formula1", "formula2"):
value = getattr(data_validation, attr, None)
if value is not None:
f = Element("{%s}%s" % (SHEET_MAIN_NS, attr))
f.text = value
el.append(f)
return el
示例7: to_tree
# 需要导入模块: from openpyxl.xml.functions import Element [as 别名]
# 或者: from openpyxl.xml.functions.Element import text [as 别名]
def to_tree(self, tagname=None, idx=None, namespace=None):
if tagname is None:
tagname = self.tagname
# keywords have to be masked
if tagname.startswith("_"):
tagname = tagname[1:]
tagname = namespaced(self, tagname, namespace)
namespace = getattr(self, "namespace", namespace)
attrs = dict(self)
for key, ns in self.__namespaced__:
if key in attrs:
attrs[ns] = attrs[key]
del attrs[key]
el = Element(tagname, attrs)
if "attr_text" in self.__attrs__:
el.text = safe_string(getattr(self, "attr_text"))
for child_tag in self.__elements__:
desc = getattr(self.__class__, child_tag, None)
obj = getattr(self, child_tag)
if isinstance(obj, seq_types):
if isinstance(desc, NestedSequence):
# wrap sequence in container
if not obj:
continue
nodes = [desc.to_tree(child_tag, obj, namespace)]
elif isinstance(desc, Sequence):
# sequence
desc.idx_base = self.idx_base
nodes = (desc.to_tree(child_tag, obj, namespace))
else: # property
nodes = (v.to_tree(child_tag, namespace) for v in obj)
for node in nodes:
el.append(node)
else:
if child_tag in self.__nested__:
node = desc.to_tree(child_tag, obj, namespace)
elif obj is None:
continue
else:
node = obj.to_tree(child_tag)
if node is not None:
el.append(node)
return el