def _write_series(self, subchart): for i, series in enumerate(self.chart): ser = SubElement(subchart, '{%s}ser' % CHART_NS) SubElement(ser, '{%s}idx' % CHART_NS, {'val':safe_string(i)}) SubElement(ser, '{%s}order' % CHART_NS, {'val':safe_string(i)}) if series.title: tx = SubElement(ser, '{%s}tx' % CHART_NS) SubElement(tx, '{%s}v' % CHART_NS).text = series.title if isinstance(self, LineChart): marker = SubElement(ser, "{%s}marker" % CHART_NS) SubElement(marker, "{%s}symbol" % CHART_NS, val=safe_string(series.marker)) if series.color: sppr = SubElement(ser, '{%s}spPr' % CHART_NS) self._write_series_color(sppr, series) if series.error_bar: self._write_error_bar(ser, series) if series.labels: self._write_series_labels(ser, series) if series.xvalues: self._write_series_xvalues(ser, series) val = SubElement(ser, self.series_type) self._write_serial(val, series.reference)
def __iter__(self): for attr in self.__attrs__: value = getattr(self, attr) if value and attr != "outline": yield attr, safe_string(value) elif attr == "outline" and not value: yield attr, safe_string(value)
def _write_series(self, subchart): for i, serie in enumerate(self.chart): ser = SubElement(subchart, '{%s}ser' % CHART_NS) SubElement(ser, '{%s}idx' % CHART_NS, {'val':safe_string(i)}) SubElement(ser, '{%s}order' % CHART_NS, {'val':safe_string(i)}) if serie.title: tx = SubElement(ser, '{%s}tx' % CHART_NS) SubElement(tx, '{%s}v' % CHART_NS).text = serie.title if serie.color: sppr = SubElement(ser, '{%s}spPr' % CHART_NS) self._write_series_color(sppr, serie) if serie.error_bar: self._write_error_bar(ser, serie) if serie.labels: self._write_series_labels(ser, serie) if serie.xvalues: self._write_series_xvalues(ser, serie) val = SubElement(ser, self.series_type) self._write_serial(val, serie.reference)
def _write_series(self, subchart): """write series""" for i, serie in enumerate(self.chart): ser = SubElement(subchart, '{%s}ser' % CHART_NS) SubElement(ser, '{%s}idx' % CHART_NS, {'val': safe_string(i)}) SubElement(ser, '{%s}order' % CHART_NS, {'val': safe_string(i)}) if serie.title: t_x = SubElement(ser, '{%s}t_x' % CHART_NS) SubElement(t_x, '{%s}v' % CHART_NS).text = serie.title if serie.color: sppr = SubElement(ser, '{%s}spPr' % CHART_NS) _write_series_color_node(sppr, serie) d_pt = SubElement(ser, '{%s}dPt' % CHART_NS) SubElement(d_pt, '{%s}idx' % CHART_NS, {'val': '1'}) SubElement(d_pt, '{%s}Bubble3D' % CHART_NS, {'val': '1'}) sppr = SubElement(d_pt, '{%s}spPr' % CHART_NS) fillc = SubElement(sppr, '{%s}solidFill' % DRAWING_NS) SubElement(fillc, '{%s}srgbClr' % DRAWING_NS, {'val': 'FFFF00'}) if serie.error_bar: _write_error_bar(ser, serie) if serie.labels: _write_series_labels(ser, serie) if serie.xvalues: _write_series_xvalues(ser, serie) val = SubElement(ser, self.series_type) _write_serial(val, serie.reference)
def _write_axis(self, plot_area, axis, label): if self.chart.auto_axis: self.chart.compute_axes() ax = SubElement(plot_area, label) SubElement(ax, "{%s}axId" % CHART_NS, {"val": safe_string(axis.id)}) scaling = SubElement(ax, "{%s}scaling" % CHART_NS) SubElement(scaling, "{%s}orientation" % CHART_NS, {"val": axis.orientation}) if axis.delete_axis: SubElement(scaling, "{%s}" % CHART_NS, {"val": "1"}) if axis.type == "valAx": SubElement(scaling, "{%s}max" % CHART_NS, {"val": str(float(axis.max))}) SubElement(scaling, "{%s}min" % CHART_NS, {"val": str(float(axis.min))}) SubElement(ax, "{%s}axPos" % CHART_NS, {"val": axis.position}) if axis.type == "valAx": SubElement(ax, "{%s}majorGridlines" % CHART_NS) SubElement(ax, "{%s}numFmt" % CHART_NS, {"formatCode": "General", "sourceLinked": "1"}) self._write_axis_title(axis, ax) SubElement(ax, "{%s}tickLblPos" % CHART_NS, {"val": axis.tick_label_position}) SubElement(ax, "{%s}crossAx" % CHART_NS, {"val": str(axis.cross)}) SubElement(ax, "{%s}crosses" % CHART_NS, {"val": axis.crosses}) if axis.auto: SubElement(ax, "{%s}auto" % CHART_NS, {"val": "1"}) if axis.label_align: SubElement(ax, "{%s}lblAlgn" % CHART_NS, {"val": axis.label_align}) if axis.label_offset: SubElement(ax, "{%s}lblOffset" % CHART_NS, {"val": str(axis.label_offset)}) if axis.type == "valAx": SubElement(ax, "{%s}crossBetween" % CHART_NS, {"val": axis.cross_between}) SubElement(ax, "{%s}majorUnit" % CHART_NS, {"val": safe_string(axis.unit)})
def _write_series(self, subchart): """write series""" for i, serie in enumerate(self.chart): ser = SubElement(subchart, '{%s}ser' % CHART_NS) SubElement(ser, '{%s}idx' % CHART_NS, {'val': safe_string(i)}) SubElement(ser, '{%s}order' % CHART_NS, {'val': safe_string(i)}) if serie.title: t_x = SubElement(ser, '{%s}tx' % CHART_NS) SubElement(t_x, '{%s}v' % CHART_NS).text = serie.title if serie.color: sppr = SubElement(ser, '{%s}spPr' % CHART_NS) _write_series_color_node(sppr, serie) d_pt = SubElement(ser, '{%s}dPt' % CHART_NS) SubElement(d_pt, '{%s}idx' % CHART_NS, {'val': '1'}) sppr = SubElement(d_pt, '{%s}spPr' % CHART_NS) fillc = SubElement(sppr, '{%s}solidFill' % DRAWING_NS) SubElement(fillc, '{%s}srgbClr' % DRAWING_NS, {'val': 'FF0000'}) d_pt = SubElement(ser, '{%s}dPt' % CHART_NS) SubElement(d_pt, '{%s}idx' % CHART_NS, {'val': '2'}) sppr = SubElement(d_pt, '{%s}spPr' % CHART_NS) fillc = SubElement(sppr, '{%s}solidFill' % DRAWING_NS) SubElement(fillc, '{%s}srgbClr' % DRAWING_NS, {'val': '777777'}) d_lbls = SubElement(ser, '{%s}dLbls' % CHART_NS) SubElement(d_lbls, '{%s}dLblPos' % DRAWING_NS, {'val': 'outEnd'}) SubElement(d_lbls, '{%s}showLegendKey' % DRAWING_NS, {'val': '1'}) SubElement(d_lbls, '{%s}showVal' % DRAWING_NS, {'val': '0'}) SubElement(d_lbls, '{%s}showCatName' % DRAWING_NS, {'val': '0'}) SubElement(d_lbls, '{%s}showSerName' % DRAWING_NS, {'val': '0'}) SubElement(d_lbls, '{%s}showPercent' % DRAWING_NS, {'val': '1'}) SubElement(d_lbls, '{%s}showBubbleSize' % DRAWING_NS, {'val': '0'}) SubElement(d_lbls, '{%s}showLeaderLines' % DRAWING_NS, {'val': '0'}) if serie.error_bar: _write_error_bar(ser, serie) if serie.labels: _write_series_labels(ser, serie) if serie.xvalues: _write_series_xvalues(ser, serie) val = SubElement(ser, self.series_type) _write_serial(val, serie.reference)
def __iter__(self): for attr in ('type', 'allowBlank', 'operator', 'sqref', 'showInputMessage', 'showErrorMessage', 'errorTitle', 'error', 'errorStyle', 'promptTitle', 'prompt'): value = getattr(self, attr) if value is not None: yield attr, safe_string(value)
def __iter__(self): for key in self.__fields__: value = getattr(self, key, None) if key in ('style', 's'): value = self.style_id if value: yield key, safe_string(value)
def write_cell(worksheet, cell): string_table = worksheet.parent.shared_strings coordinate = cell.coordinate attributes = {'r': coordinate} if cell.has_style: attributes['s'] = '%d' % cell._style if cell.data_type != 'f': attributes['t'] = cell.data_type value = cell.internal_value el = Element("c", attributes) if value in ('', None): return el if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(coordinate, {}) if shared_formula is not None: if (shared_formula.get('t') == 'shared' and 'ref' not in shared_formula): value = None formula = SubElement(el, 'f', shared_formula) if value is not None: formula.text= value[1:] value = None if cell.data_type == 's': value = string_table.add(value) cell_content = SubElement(el, 'v') if value is not None: cell_content.text = safe_string(value) return el
def _write_axis(self, plot_area, axis, label): if self.chart.auto_axis: self.chart.compute_axes() ax = SubElement(plot_area, label) SubElement(ax, '{%s}axId' % CHART_NS, {'val':safe_string(axis.id)}) scaling = SubElement(ax, '{%s}scaling' % CHART_NS) SubElement(scaling, '{%s}orientation' % CHART_NS, {'val':axis.orientation}) if axis.delete_axis: SubElement(scaling, '{%s}' % CHART_NS, {'val':'1'}) if axis.type == "valAx": SubElement(scaling, '{%s}max' % CHART_NS, {'val':str(float(axis.max))}) SubElement(scaling, '{%s}min' % CHART_NS, {'val':str(float(axis.min))}) SubElement(ax, '{%s}axPos' % CHART_NS, {'val':axis.position}) if axis.type == "valAx": SubElement(ax, '{%s}majorGridlines' % CHART_NS) SubElement(ax, '{%s}numFmt' % CHART_NS, {'formatCode':"General", 'sourceLinked':'1'}) self._write_axis_title(axis, ax) SubElement(ax, '{%s}tickLblPos' % CHART_NS, {'val':axis.tick_label_position}) SubElement(ax, '{%s}crossAx' % CHART_NS, {'val':str(axis.cross)}) SubElement(ax, '{%s}crosses' % CHART_NS, {'val':axis.crosses}) if axis.auto: SubElement(ax, '{%s}auto' % CHART_NS, {'val':'1'}) if axis.label_align: SubElement(ax, '{%s}lblAlgn' % CHART_NS, {'val':axis.label_align}) if axis.label_offset: SubElement(ax, '{%s}lblOffset' % CHART_NS, {'val':str(axis.label_offset)}) if axis.type == "valAx": SubElement(ax, '{%s}crossBetween' % CHART_NS, {'val':axis.cross_between}) SubElement(ax, '{%s}majorUnit' % CHART_NS, {'val':str(float(axis.unit))})
def _explicit_none(tagname, value, namespace=None): """ Override serialisation because explicit none required """ if namespace is not None: tagname = "{%s}%s" % (namespace, tagname) return Element(tagname, val=safe_string(value))
def write_cell(xf, worksheet, cell): string_table = worksheet.parent.shared_strings coordinate = cell.coordinate attributes = {'r': coordinate} if cell.has_style: attributes['s'] = '%d' % cell._style if cell.data_type != 'f': attributes['t'] = cell.data_type value = cell.internal_value if value in ('', None): with xf.element("c", attributes): return with xf.element('c', attributes): if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(coordinate, {}) if shared_formula is not None: if (shared_formula.get('t') == 'shared' and 'ref' not in shared_formula): value = None with xf.element('f', shared_formula): if value is not None: xf.write(value[1:]) value = None if cell.data_type == 's': value = string_table.add(value) with xf.element("v"): if value is not None: xf.write(safe_string(value))
def write_cell(xf, worksheet, cell, styled=False): coordinate = cell.coordinate attributes = {'r': coordinate} if styled: attributes['s'] = '%d' % cell.style_id if cell.data_type != 'f': attributes['t'] = cell.data_type value = cell._value if value == '' or value is None: with xf.element("c", attributes): return with xf.element('c', attributes): if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(coordinate, {}) with xf.element('f', shared_formula): if value is not None: xf.write(value[1:]) value = None if cell.data_type == 's': value = worksheet.parent.shared_strings.add(value) with xf.element("v"): if value is not None: xf.write(safe_string(value))
def __iter__(self): for attr in ( "orientation", "paperSize", "scale", "fitToHeight", "fitToWidth", "firstPageNumber", "useFirstPageNumber", "paperHeight", "paperWidth", "pageOrder", "usePrinterDefaults", "blackAndWhite", "draft", "cellComments", "errors", "horizontalDpi", "verticalDpi", "copies", "id", ): value = getattr(self, attr) if value is not None: yield attr, safe_string(value)
def to_tree(self, tagname=None): if tagname is None: tagname = self.tagname attrs = dict(self) el = Element(tagname, attrs) for n in self.__nested__: value = getattr(self, n) if isinstance(value, tuple): if hasattr(el, 'extend'): el.extend(self._serialise_nested(value)) else: # py26 nolxml for _ in self._serialise_nested(value): el.append(_) elif value: SubElement(el, n, val=safe_string(value)) for child in self.__elements__: obj = getattr(self, child) if isinstance(obj, tuple): for v in obj: if hasattr(v, 'to_tree'): el.append(v.to_tree(tagname=child)) else: SubElement(el, child).text = v elif obj is not None: el.append(obj.to_tree(tagname=child)) return el
def __iter__(self): for attr in self.__attrs__: value = getattr(self, attr) if attr.startswith("_"): attr = attr[1:] if attr != "attr_text" and value is not None: yield attr, safe_string(value)
def lxml_write_cell(xf, worksheet, cell, styled=False): value, attributes = _set_attributes(cell, styled) if value == '' or value is None: with xf.element("c", attributes): return with xf.element('c', attributes): if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(cell.coordinate, {}) with xf.element('f', shared_formula): if value is not None: xf.write(value[1:]) value = None if cell.data_type == 's': with xf.element("is"): attrs = {} if value != value.strip(): attrs["{%s}space" % XML_NS] = "preserve" el = Element("t", attrs) # lxml can't handle xml-ns el.text = value xf.write(el) #with xf.element("t", attrs): #xf.write(value) else: with xf.element("v"): if value is not None: xf.write(safe_string(value))
def write_cell(doc, worksheet, cell, string_table): coordinate = cell.coordinate attributes = {'r': coordinate} cell_style = worksheet._styles.get(coordinate) if cell_style is not None: attributes['s'] = '%d' % cell_style if cell.data_type != cell.TYPE_FORMULA: attributes['t'] = cell.data_type value = cell.internal_value if value in ('', None): tag(doc, 'c', attributes) else: start_tag(doc, 'c', attributes) if cell.data_type == cell.TYPE_STRING: tag(doc, 'v', body='%s' % string_table.index(value)) elif cell.data_type == cell.TYPE_FORMULA: shared_formula = worksheet.formula_attributes.get(coordinate) if shared_formula is not None: attr = shared_formula if 't' in attr and attr['t'] == 'shared' and 'ref' not in attr: # Don't write body for shared formula tag(doc, 'f', attr=attr) else: tag(doc, 'f', attr=attr, body=value[1:]) else: tag(doc, 'f', body=value[1:]) tag(doc, 'v') elif cell.data_type in (cell.TYPE_NUMERIC, cell.TYPE_BOOL): tag(doc, 'v', body=safe_string(value)) else: tag(doc, 'v', body=value) end_tag(doc, 'c')
def _write_serial(self, node, reference, literal=False): is_ref = hasattr(reference, "pos1") data_type = reference.data_type number_format = getattr(reference, "number_format") mapping = {"n": {"ref": "numRef", "cache": "numCache"}, "s": {"ref": "strRef", "cache": "strCache"}} # data = None if is_ref: ref = SubElement(node, "{%s}%s" % (CHART_NS, mapping[data_type]["ref"])) SubElement(ref, "{%s}f" % CHART_NS).text = str(reference) data = SubElement(ref, "{%s}%s" % (CHART_NS, mapping[data_type]["cache"])) values = reference.values else: data = SubElement(node, "{%s}numLit" % CHART_NS) values = (1,) if data_type == "n": SubElement(data, "{%s}formatCode" % CHART_NS).text = number_format or "General" # if data is not None: SubElement(data, "{%s}ptCount" % CHART_NS, {"val": str(len(values))}) for j, val in enumerate(values): if val is not None: val = safe_string(val) else: val = "" point = SubElement(data, "{%s}pt" % CHART_NS, idx="%d" % j) SubElement(point, "{%s}v" % CHART_NS).text = val
def vba_code(self): for attr in ("codeName", "enableFormatConditionsCalculation", "filterMode", "published", "syncHorizontal", "syncRef", "syncVertical", "transitionEvaluation", "transitionEntry"): value = getattr(self.sheet_properties, attr) if value is not None: yield attr, safe_string(value)
def write_cell(doc, worksheet, cell): string_table = worksheet.parent.shared_strings coordinate = cell.coordinate attributes = {'r': coordinate} if cell.has_style: attributes['s'] = '%d' % cell._style if cell.data_type != cell.TYPE_FORMULA: attributes['t'] = cell.data_type value = cell.internal_value if value in ('', None): tag(doc, 'c', attributes) else: start_tag(doc, 'c', attributes) if cell.data_type == cell.TYPE_STRING: idx = string_table.add(value) tag(doc, 'v', body='%s' % idx) elif cell.data_type == cell.TYPE_FORMULA: shared_formula = worksheet.formula_attributes.get(coordinate) if shared_formula is not None: attr = shared_formula if 't' in attr and attr['t'] == 'shared' and 'ref' not in attr: # Don't write body for shared formula tag(doc, 'f', attr=attr) else: tag(doc, 'f', attr=attr, body=value[1:]) else: tag(doc, 'f', body=value[1:]) tag(doc, 'v') elif cell.data_type in (cell.TYPE_NUMERIC, cell.TYPE_BOOL): tag(doc, 'v', body=safe_string(value)) else: tag(doc, 'v', body=value) end_tag(doc, 'c')
def write_cell(worksheet, cell, styled=None): coordinate = cell.coordinate attributes = {'r': coordinate} if styled: attributes['s'] = '%d' % cell.style_id if cell.data_type != 'f': attributes['t'] = cell.data_type value = cell._value el = Element("c", attributes) if value is None or value == "": return el if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(coordinate, {}) if (shared_formula.get('t') == 'shared' and 'ref' not in shared_formula): value = None formula = SubElement(el, 'f', shared_formula) if value is not None: formula.text = value[1:] value = None if cell.data_type == 's': value = worksheet.parent.shared_strings.add(value) cell_content = SubElement(el, 'v') if value is not None: cell_content.text = safe_string(value) return el
def __iter__(self): for attr in ('type', 'allowBlank', 'operator', 'sqref', 'showInputMessage', 'showErrorMessage', 'errorTitle', 'error', 'promptTitle', 'prompt'): value = getattr(self, attr) if value is not None: yield attr, safe_string(value)
def _marker_symbol(tagname, value, namespace=None): """ Override serialisation because explicit none required """ if namespace is not None: tagname = "{%s}%s" % (namespace, tagname) return Element(tagname, val=safe_string(value))
def etree_write_cell(xf, worksheet, cell, styled=None): value, attributes = _set_attributes(cell, styled) el = Element("c", attributes) if value is None or value == "": xf.write(el) return if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(cell.coordinate, {}) formula = SubElement(el, 'f', shared_formula) if value is not None: formula.text = value[1:] value = None if cell.data_type == 's': inline_string = SubElement(el, 'is') text = SubElement(inline_string, 't') text.text = value whitespace(text) else: cell_content = SubElement(el, 'v') if value is not None: cell_content.text = safe_string(value) xf.write(el)
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) value = safe_string(value) return Element(tagname, {self.attribute: value})
def write_cell(xf, worksheet, cell, string_table): coordinate = cell.coordinate attributes = {'r': coordinate} cell_style = worksheet._styles.get(coordinate) if cell_style is not None: attributes['s'] = '%d' % cell_style if cell.data_type != 'f': attributes['t'] = cell.data_type value = cell.internal_value if value in ('', None): with xf.element("c", attributes): return with xf.element('c', attributes): if cell.data_type == 'f': shared_formula = worksheet.formula_attributes.get(coordinate, {}) if shared_formula is not None: if (shared_formula.get('t') == 'shared' and 'ref' not in shared_formula): value = None with xf.element('f', shared_formula): if value is not None: xf.write(value[1:]) value = None if cell.data_type == 's': value = string_table.index(value) with xf.element("v") as v: if value is not None: xf.write(safe_string(value))
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) value = safe_string(value) return Element(tagname, {self.attribute:value})
def _write_print_settings(self): settings = SubElement(self.root, '{%s}printSettings' % CHART_NS) SubElement(settings, '{%s}headerFooter' % CHART_NS) margins = dict([(k, safe_string(v)) for (k, v) in iteritems(self.chart.print_margins)]) SubElement(settings, '{%s}pageMargins' % CHART_NS, margins) SubElement(settings, '{%s}pageSetup' % CHART_NS)
def _write_serial(self, node, reference, literal=False): is_ref = hasattr(reference, 'pos1') data_type = reference.data_type number_format = getattr(reference, 'number_format') mapping = {'n':{'ref':'numRef', 'cache':'numCache'}, 's':{'ref':'strRef', 'cache':'strCache'}} if is_ref: ref = SubElement(node, '{%s}%s' %(CHART_NS, mapping[data_type]['ref'])) SubElement(ref, '{%s}f' % CHART_NS).text = str(reference) data = SubElement(ref, '{%s}%s' %(CHART_NS, mapping[data_type]['cache'])) values = reference.values else: data = SubElement(node, '{%s}numLit' % CHART_NS) values = (1,) if data_type == 'n': SubElement(data, '{%s}formatCode' % CHART_NS).text = number_format or 'General' SubElement(data, '{%s}ptCount' % CHART_NS, {'val':str(len(values))}) for j, val in enumerate(values): point = SubElement(data, '{%s}pt' % CHART_NS, {'idx':str(j)}) val = safe_string(val) SubElement(point, '{%s}v' % CHART_NS).text = val
def __iter__(self): """ Dictionary interface for easier serialising. All values converted to strings """ for key in self.__fields__: value = getattr(self, key) yield key, safe_string(value)
def __iter__(self): for key in self.__fields__[1:]: if key == 'style': value = getattr(self, '_style') else: value = getattr(self, key) if value: yield key, safe_string(value)
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
def __iter__(self): for attr in self.__attrs__: value = getattr(self, attr) if attr == 'showGridLines' and value: continue if value is not None: yield attr, safe_string(value)
def __iter__(self): """ Unset outline defaults to True, others default to False """ for key in ('diagonalUp', 'diagonalDown', 'outline'): value = getattr(self, key) if (key == "outline" and not value or key != "outline" and value): yield key, safe_string(value)
def __iter__(self): for key in self.__fields__: if key == "style": value = self.style_id else: value = getattr(self, key) if value: yield key, safe_string(value)
def __iter__(self): for key in self.__attrs__: if key == "attr_text": continue v = getattr(self, key) if v is not None: if v in RESERVED: v = "_xlnm." + v yield key, safe_string(v)
def __iter__(self): for key in ('sheet', 'objects', 'scenarios', 'formatCells', 'formatRows', 'formatColumns', 'insertColumns', 'insertRows', 'insertHyperlinks', 'deleteColumns', 'deleteRows', 'selectLockedCells', 'selectUnlockedCells', 'sort', 'autoFilter', 'pivotTables', 'password', 'algorithmName', 'saltValue', 'spinCount'): value = getattr(self, key) if value is not None: yield key, safe_string(value)
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