class _AnchorBase(Serialisable): #one of sp = Typed(expected_type=Shape, allow_none=True) shape = Alias("sp") grpSp = Typed(expected_type=GroupShape, allow_none=True) groupShape = Alias("grpSp") graphicFrame = Typed(expected_type=GraphicFrame, allow_none=True) cxnSp = Typed(expected_type=Shape, allow_none=True) connectionShape = Alias("cxnSp") pic = Typed(expected_type=PictureFrame, allow_none=True) contentPart = Relation() clientData = Typed(expected_type=AnchorClientData) __elements__ = ('sp', 'grpSp', 'graphicFrame', 'cxnSp', 'pic', 'contentPart', 'clientData') def __init__(self, clientData=None, sp=None, grpSp=None, graphicFrame=None, cxnSp=None, pic=None, contentPart=None): if clientData is None: clientData = AnchorClientData() self.clientData = clientData self.sp = sp self.grpSp = grpSp self.graphicFrame = graphicFrame self.cxnSp = cxnSp self.pic = pic self.contentPart = contentPart
class RelativeRect(Serialisable): tagname = "rect" namespace = DRAWING_NS l = MinMax(min=0, max=100000, allow_none=True) left = Alias('l') t = MinMax(min=0, max=100000, allow_none=True) top = Alias('t') r = MinMax(min=0, max=100000, allow_none=True) right = Alias('r') b = MinMax(min=0, max=100000, allow_none=True) bottom = Alias('b') def __init__( self, l=None, t=None, r=None, b=None, ): self.l = l self.t = t self.r = r self.b = b
class TrendlineLabel(Serialisable): tagname = "trendlineLbl" layout = Typed(expected_type=Layout, allow_none=True) tx = Typed(expected_type=Text, allow_none=True) numFmt = Typed(expected_type=NumFmt, allow_none=True) spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias("spPr") txPr = Typed(expected_type=RichText, allow_none=True) textProperties = Alias("txPr") extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('layout', 'tx', 'numFmt', 'spPr', 'txPr') def __init__( self, layout=None, tx=None, numFmt=None, spPr=None, txPr=None, extLst=None, ): self.layout = layout self.tx = tx self.numFmt = numFmt self.spPr = spPr self.txPr = txPr
class ConditionalFormatting(Serialisable): tagname = "conditionalFormatting" sqref = Convertible(expected_type=MultiCellRange) cells = Alias("sqref") pivot = Bool(allow_none=True) cfRule = Sequence(expected_type=Rule) rules = Alias("cfRule") def __init__(self, sqref=(), pivot=None, cfRule=(), extLst=None): self.sqref = sqref self.pivot = pivot self.cfRule = cfRule def __eq__(self, other): if not isinstance(other, self.__class__): return False return self.sqref == other.sqref def __hash__(self): return hash(str(self.sqref)) def __repr__(self): return "<{cls} {cells}>".format(cls=self.__class__.__name__, cells=self.sqref) def __contains__(self, coord): """ Check whether a certain cell is affected by the formatting """ return coord in self.sqref
class PatternFillProperties(Serialisable): tagname = "pattFill" namespace = DRAWING_NS prst = NoneSet(values=([ 'pct5', 'pct10', 'pct20', 'pct25', 'pct30', 'pct40', 'pct50', 'pct60', 'pct70', 'pct75', 'pct80', 'pct90', 'horz', 'vert', 'ltHorz', 'ltVert', 'dkHorz', 'dkVert', 'narHorz', 'narVert', 'dashHorz', 'dashVert', 'cross', 'dnDiag', 'upDiag', 'ltDnDiag', 'ltUpDiag', 'dkDnDiag', 'dkUpDiag', 'wdDnDiag', 'wdUpDiag', 'dashDnDiag', 'dashUpDiag', 'diagCross', 'smCheck', 'lgCheck', 'smGrid', 'lgGrid', 'dotGrid', 'smConfetti', 'lgConfetti', 'horzBrick', 'diagBrick', 'solidDmnd', 'openDmnd', 'dotDmnd', 'plaid', 'sphere', 'weave', 'divot', 'shingle', 'wave', 'trellis', 'zigZag' ])) preset = Alias("prst") fgClr = Typed(expected_type=ColorChoice, allow_none=True) foreground = Alias("fgClr") bgClr = Typed(expected_type=ColorChoice, allow_none=True) background = Alias("bgClr") __elements__ = ("fgClr", "bgClr") def __init__( self, prst=None, fgClr=None, bgClr=None, ): self.prst = prst self.fgClr = fgClr self.bgClr = bgClr
class GradientFillProperties(Serialisable): tagname = "gradFill" flip = NoneSet(values=(['x', 'y', 'xy'])) rotWithShape = Bool(allow_none=True) gsLst = Typed(expected_type=GradientStopList, allow_none=True) stop_list = Alias("gsLst") lin = Typed(expected_type=LinearShadeProperties, allow_none=True) linear = Alias("lin") path = Typed(expected_type=PathShadeProperties, allow_none=True) tileRect = Typed(expected_type=RelativeRect, allow_none=True) __elements__ = ('gsLst', 'lin', 'path', 'tileRect') def __init__( self, flip=None, rotWithShape=None, gsLst=None, lin=None, path=None, tileRect=None, ): self.flip = flip self.rotWithShape = rotWithShape self.gsLst = gsLst self.lin = lin self.path = path self.tileRect = tileRect
class RichText(Serialisable): """ From the specification: 21.2.2.216 This element specifies text formatting. The lstStyle element is not supported. """ tagname = "rich" bodyPr = Typed(expected_type=RichTextProperties) properties = Alias("bodyPr") lstStyle = Typed(expected_type=ListStyle, allow_none=True) p = Sequence(expected_type=Paragraph) paragraphs = Alias('p') __elements__ = ("bodyPr", "lstStyle", "p") def __init__(self, bodyPr=None, lstStyle=None, p=None, ): if bodyPr is None: bodyPr = RichTextProperties() self.bodyPr = bodyPr self.lstStyle = lstStyle if p is None: p = [Paragraph()] self.p = p
class _BarChartBase(ChartBase): barDir = NestedSet(values=(['bar', 'col'])) type = Alias("barDir") grouping = NestedSet(values=(['percentStacked', 'clustered', 'standard', 'stacked'])) varyColors = NestedBool(nested=True, allow_none=True) ser = Sequence(expected_type=Series, allow_none=True) dLbls = Typed(expected_type=DataLabelList, allow_none=True) dataLabels = Alias("dLbls") __elements__ = ('barDir', 'grouping', 'varyColors', 'ser', 'dLbls') _series_type = "bar" def __init__(self, barDir="col", grouping="clustered", varyColors=None, ser=(), dLbls=None, **kw ): self.barDir = barDir self.grouping = grouping self.varyColors = varyColors self.ser = ser self.dLbls = dLbls super(_BarChartBase, self).__init__(**kw)
class RadarChart(ChartBase): tagname = "radarChart" radarStyle = NestedSet(values=(['standard', 'marker', 'filled'])) type = Alias("radarStyle") varyColors = NestedBool(nested=True, allow_none=True) ser = Sequence(expected_type=Series, allow_none=True) dLbls = Typed(expected_type=DataLabelList, allow_none=True) dataLabels = Alias("dLbls") extLst = Typed(expected_type=ExtensionList, allow_none=True) _series_type = "radar" x_axis = Typed(expected_type=TextAxis) y_axis = Typed(expected_type=NumericAxis) __elements__ = ('radarStyle', 'varyColors', 'ser', 'dLbls', 'axId') def __init__(self, radarStyle="standard", varyColors=None, ser=(), dLbls=None, extLst=None, **kw): self.radarStyle = radarStyle self.varyColors = varyColors self.ser = ser self.dLbls = dLbls self.x_axis = TextAxis() self.y_axis = NumericAxis() super(RadarChart, self).__init__(**kw)
class DisplayUnitsLabel(Serialisable): tagname = "dispUnitsLbl" layout = Typed(expected_type=Layout, allow_none=True) tx = Typed(expected_type=Text, allow_none=True) text = Alias("tx") spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias("spPr") txPr = Typed(expected_type=RichText, allow_none=True) textPropertes = Alias("txPr") __elements__ = ('layout', 'tx', 'spPr', 'txPr') def __init__( self, layout=None, tx=None, spPr=None, txPr=None, ): self.layout = layout self.tx = tx self.spPr = spPr self.txPr = txPr
class Title(Serialisable): tagname = "title" tx = Typed(expected_type=Text, allow_none=True) text = Alias('tx') layout = Typed(expected_type=Layout, allow_none=True) overlay = NestedBool(allow_none=True) spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias('spPr') txPr = Typed(expected_type=RichText, allow_none=True) body = Alias('txPr') extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('tx', 'layout', 'overlay', 'spPr', 'txPr') def __init__(self, tx=None, layout=None, overlay=None, spPr=None, txPr=None, extLst=None, ): if tx is None: tx = Text() self.tx = tx self.layout = layout self.overlay = overlay self.spPr = spPr self.txPr = txPr
class ColorChoice(Serialisable): tagname = "colorChoice" namespace = DRAWING_NS scrgbClr = Typed(expected_type=RGBPercent, allow_none=True) RGBPercent = Alias('scrgbClr') srgbClr = NestedValue(expected_type=unicode, allow_none=True) # needs pattern and can have transform RGB = Alias('srgbClr') hslClr = Typed(expected_type=HSLColor, allow_none=True) sysClr = Typed(expected_type=SystemColor, allow_none=True) schemeClr = Typed(expected_type=SchemeColor, allow_none=True) prstClr = NestedNoneSet(values=PRESET_COLORS) __elements__ = ('scrgbClr', 'srgbClr', 'hslClr', 'sysClr', 'schemeClr', 'prstClr') def __init__(self, scrgbClr=None, srgbClr=None, hslClr=None, sysClr=None, schemeClr=None, prstClr=None, ): self.scrgbClr = scrgbClr self.srgbClr = srgbClr self.hslClr = hslClr self.sysClr = sysClr self.schemeClr = schemeClr self.prstClr = prstClr
class Paragraph(Serialisable): tagname = "p" namespace = DRAWING_NS # uses element group EG_TextRun pPr = Typed(expected_type=ParagraphProperties, allow_none=True) properties = Alias("pPr") endParaRPr = Typed(expected_type=CharacterProperties, allow_none=True) r = Sequence(expected_type=RegularTextRun) text = Alias('r') br = Typed(expected_type=LineBreak, allow_none=True) fld = Typed(expected_type=TextField, allow_none=True) __elements__ = ('pPr', 'r', 'br', 'fld', 'endParaRPr') def __init__(self, pPr=None, endParaRPr=None, r=None, br=None, fld=None, ): self.pPr = pPr self.endParaRPr = endParaRPr if r is None: r = [RegularTextRun()] self.r = r self.br = br self.fld = fld
class Relationship(Serialisable): """Represents many kinds of relationships.""" tagname = "Relationship" Type = String() Target = String() target = Alias("Target") TargetMode = String(allow_none=True) Id = String(allow_none=True) id = Alias("Id") def __init__(self, Id=None, Type=None, type=None, Target=None, TargetMode=None): """ `type` can be used as a shorthand with the default relationships namespace otherwise the `Type` must be a fully qualified URL """ if type is not None: Type = "{0}/{1}".format(REL_NS, type) self.Type = Type self.Target = Target self.TargetMode = TargetMode self.Id = Id
class RowDimension(Dimension): """Information about the display properties of a row.""" __fields__ = Dimension.__fields__ + ('ht', 'customFormat', 'customHeight', 's', 'thickBot', 'thickTop') r = Alias('index') s = Alias('style_id') ht = Float(allow_none=True) height = Alias('ht') thickBot = Bool() thickTop = Bool() def __init__( self, worksheet, index=0, ht=None, customHeight=None, # do not write s=None, customFormat=None, # do not write hidden=False, outlineLevel=0, outline_level=None, collapsed=False, visible=None, height=None, r=None, spans=None, thickBot=None, thickTop=None, **kw): if r is not None: index = r if height is not None: ht = height self.ht = ht if visible is not None: hidden = not visible if outline_level is not None: outlineLevel = outlineLevel self.thickBot = thickBot self.thickTop = thickTop super(RowDimension, self).__init__(index, hidden, outlineLevel, collapsed, worksheet, style=s) @property def customFormat(self): """Always true if there is a style for the row""" return self.has_style @property def customHeight(self): """Always true if there is a height for the row""" return self.ht is not None
class _DataLabelBase(Serialisable): numFmt = NestedString(allow_none=True, attribute="formatCode") spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias('spPr') txPr = Typed(expected_type=RichText, allow_none=True) textProperties = Alias('txPr') dLblPos = NestedNoneSet(values=[ 'bestFit', 'b', 'ctr', 'inBase', 'inEnd', 'l', 'outEnd', 'r', 't' ]) position = Alias('dLblPos') showLegendKey = NestedBool(allow_none=True) showVal = NestedBool(allow_none=True) showCatName = NestedBool(allow_none=True) showSerName = NestedBool(allow_none=True) showPercent = NestedBool(allow_none=True) showBubbleSize = NestedBool(allow_none=True) showLeaderLines = NestedBool(allow_none=True) separator = NestedString(allow_none=True) extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ("numFmt", "spPr", "txPr", "dLblPos", "showLegendKey", "showVal", "showCatName", "showSerName", "showPercent", "showBubbleSize", "showLeaderLines", "separator") def __init__( self, numFmt=None, spPr=None, txPr=None, dLblPos=None, showLegendKey=None, showVal=None, showCatName=None, showSerName=None, showPercent=None, showBubbleSize=None, showLeaderLines=None, separator=None, extLst=None, ): self.numFmt = numFmt self.spPr = spPr self.txPr = txPr self.dLblPos = dLblPos self.showLegendKey = showLegendKey self.showVal = showVal self.showCatName = showCatName self.showSerName = showSerName self.showPercent = showPercent self.showBubbleSize = showBubbleSize self.showLeaderLines = showLeaderLines self.separator = separator
class PatternFill(Fill): """Area fill patterns for use in styles. Caution: if you do not specify a fill_type, other attributes will have no effect !""" tagname = "patternFill" __elements__ = ('fgColor', 'bgColor') patternType = NoneSet(values=fills) fill_type = Alias("patternType") fgColor = ColorDescriptor() start_color = Alias("fgColor") bgColor = ColorDescriptor() end_color = Alias("bgColor") def __init__(self, patternType=None, fgColor=Color(), bgColor=Color(), fill_type=None, start_color=None, end_color=None): if fill_type is not None: patternType = fill_type self.patternType = patternType if start_color is not None: fgColor = start_color self.fgColor = fgColor if end_color is not None: bgColor = end_color self.bgColor = bgColor @classmethod def _from_tree(cls, el): attrib = dict(el.attrib) for child in el: desc = localname(child) attrib[desc] = Color.from_tree(child) return cls(**attrib) def to_tree(self, tagname=None, idx=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
class ProjectedPieChart(_PieChartBase): """ From the spec 21.2.2.126 This element contains the pie of pie or bar of pie series on this chart. Only the first series shall be displayed. The splitType element shall determine whether the splitPos and custSplit elements apply. """ tagname = "ofPieChart" varyColors = _PieChartBase.varyColors ser = _PieChartBase.ser dLbls = _PieChartBase.dLbls ofPieType = NestedSet(values=(['pie', 'bar'])) type = Alias('ofPieType') gapWidth = NestedGapAmount() splitType = NestedNoneSet(values=(['auto', 'cust', 'percent', 'pos', 'val'])) splitPos = NestedFloat(allow_none=True) custSplit = Typed(expected_type=CustomSplit, allow_none=True) secondPieSize = NestedMinMax(min=5, max=200, allow_none=True) serLines = Typed(expected_type=ChartLines, allow_none=True) join_lines = Alias('serLines') extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = _PieChartBase.__elements__ + ('ofPieType', 'gapWidth', 'splitType', 'splitPos', 'custSplit', 'secondPieSize', 'serLines') def __init__(self, ofPieType="pie", gapWidth=None, splitType="auto", splitPos=None, custSplit=None, secondPieSize=75, serLines=None, extLst=None, **kw ): self.ofPieType = ofPieType self.gapWidth = gapWidth self.splitType = splitType self.splitPos = splitPos self.custSplit = custSplit self.secondPieSize = secondPieSize if serLines is None: self.serLines = ChartLines() super(ProjectedPieChart, self).__init__(**kw)
class Surface(Serialisable): tagname = "surface" thickness = NestedInteger(allow_none=True) spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias('spPr') pictureOptions = Typed(expected_type=PictureOptions, allow_none=True) extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ( 'thickness', 'spPr', 'pictureOptions', ) def __init__( self, thickness=None, spPr=None, pictureOptions=None, extLst=None, ): self.thickness = thickness self.spPr = spPr self.pictureOptions = pictureOptions
class _LineChartBase(ChartBase): grouping = NestedSet(values=(['percentStacked', 'standard', 'stacked'])) varyColors = NestedBool(allow_none=True) ser = Sequence(expected_type=Series, allow_none=True) dLbls = Typed(expected_type=DataLabelList, allow_none=True) dataLabels = Alias("dLbls") dropLines = Typed(expected_type=ChartLines, allow_none=True) _series_type = "line" __elements__ = ('grouping', 'varyColors', 'ser', 'dLbls', 'dropLines') def __init__(self, grouping="standard", varyColors=None, ser=(), dLbls=None, dropLines=None, **kw): self.grouping = grouping self.varyColors = varyColors self.ser = ser self.dLbls = dLbls self.dropLines = dropLines super(_LineChartBase, self).__init__(**kw)
class Marker(Serialisable): tagname = "marker" symbol = NestedNoneSet(values=(['circle', 'dash', 'diamond', 'dot', 'picture', 'plus', 'square', 'star', 'triangle', 'x', 'auto']), to_tree=_explicit_none) size = NestedMinMax(min=2, max=72, allow_none=True) spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias('spPr') extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('symbol', 'size', 'spPr') def __init__(self, symbol=None, size=None, spPr=None, extLst=None, ): self.symbol = symbol self.size = size if spPr is None: spPr = GraphicalProperties() self.spPr = spPr
class DataTable(Serialisable): tagname = "dTable" showHorzBorder = NestedBool(allow_none=True) showVertBorder = NestedBool(allow_none=True) showOutline = NestedBool(allow_none=True) showKeys = NestedBool(allow_none=True) spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias('spPr') txPr = Typed(expected_type=RichText, allow_none=True) extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('showHorzBorder', 'showVertBorder', 'showOutline', 'showKeys', 'spPr', 'txPr') def __init__(self, showHorzBorder=None, showVertBorder=None, showOutline=None, showKeys=None, spPr=None, txPr=None, extLst=None, ): self.showHorzBorder = showHorzBorder self.showVertBorder = showVertBorder self.showOutline = showOutline self.showKeys = showKeys self.spPr = spPr self.txPr = txPr
class DashStop(Serialisable): tagname = "ds" namespace = DRAWING_NS d = Integer() length = Alias('d') sp = Integer() space = Alias('sp') def __init__( self, d=0, sp=0, ): self.d = d self.sp = sp
class PositiveSize2D(Serialisable): """ Dimensions in EMUs """ cx = Integer() width = Alias('cx') cy = Integer() height = Alias('cy') def __init__( self, cx=None, cy=None, ): self.cx = cx self.cy = cy
class GradientFill(Fill): """Fill areas with gradient Two types of gradient fill are supported: - A type='linear' gradient interpolates colours between a set of specified Stops, across the length of an area. The gradient is left-to-right by default, but this orientation can be modified with the degree attribute. A list of Colors can be provided instead and they will be positioned with equal distance between them. - A type='path' gradient applies a linear gradient from each edge of the area. Attributes top, right, bottom, left specify the extent of fill from the respective borders. Thus top="0.2" will fill the top 20% of the cell. """ tagname = "gradientFill" type = Set(values=('linear', 'path')) fill_type = Alias("type") degree = Float() left = Float() right = Float() top = Float() bottom = Float() stop = StopList() def __init__(self, type="linear", degree=0, left=0, right=0, top=0, bottom=0, stop=()): self.degree = degree self.left = left self.right = right self.top = top self.bottom = bottom self.stop = stop self.type = type def __iter__(self): for attr in self.__attrs__: value = getattr(self, attr) if value: yield attr, safe_string(value) def to_tree(self, tagname=None, namespace=None, idx=None): parent = Element("fill") el = super(GradientFill, self).to_tree() parent.append(el) return parent
class RegularTextRun(Serialisable): tagname = "r" namespace = DRAWING_NS rPr = Typed(expected_type=CharacterProperties, allow_none=True) properties = Alias("rPr") t = NestedText(expected_type=unicode) value = Alias("t") __elements__ = ('rPr', 't') def __init__(self, rPr=None, t="", ): self.rPr = rPr self.t = t
class RichText(Serialisable): tagname = "RElt" rPr = Typed(expected_type=InlineFont, allow_none=True) font = Alias("rPr") t = NestedText(expected_type=unicode, allow_none=True) text = Alias("t") __elements__ = ('rPr', 't') def __init__( self, rPr=None, t=None, ): self.rPr = rPr self.t = t
class ChartLines(Serialisable): tagname = "chartLines" spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias('spPr') def __init__(self, spPr=None): self.spPr = spPr
class Dimension(Strict, StyleableObject): """Information about the display properties of a row or column.""" __fields__ = ( 'hidden', 'outlineLevel', 'collapsed', ) index = Integer() hidden = Bool() outlineLevel = Integer(allow_none=True) outline_level = Alias('outlineLevel') collapsed = Bool() style = Alias('style_id') def __init__(self, index, hidden, outlineLevel, collapsed, worksheet, visible=True, style=None): super(Dimension, self).__init__(sheet=worksheet, style_array=style) self.index = index self.hidden = hidden self.outlineLevel = outlineLevel self.collapsed = collapsed def __iter__(self): for key in self.__fields__: value = getattr(self, key, None) if value: yield key, safe_string(value) def __copy__(self): cp = self.__new__(self.__class__) attrib = self.__dict__ attrib['worksheet'] = self.parent cp.__init__(**attrib) cp._style = copy(self._style) return cp
class ErrorBars(Serialisable): tagname = "errBars" errDir = NestedNoneSet(values=(['x', 'y'])) direction = Alias("errDir") errBarType = NestedSet(values=(['both', 'minus', 'plus'])) style = Alias("errBarType") errValType = NestedSet( values=(['cust', 'fixedVal', 'percentage', 'stdDev', 'stdErr'])) size = Alias("errValType") noEndCap = NestedBool(nested=True, allow_none=True) plus = Typed(expected_type=NumDataSource, allow_none=True) minus = Typed(expected_type=NumDataSource, allow_none=True) val = NestedFloat(allow_none=True) spPr = Typed(expected_type=GraphicalProperties, allow_none=True) graphicalProperties = Alias("spPr") extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('errDir', 'errBarType', 'errValType', 'noEndCap', 'minus', 'plus', 'val', 'spPr') def __init__( self, errDir=None, errBarType="both", errValType="fixedVal", noEndCap=None, plus=None, minus=None, val=None, spPr=None, extLst=None, ): self.errDir = errDir self.errBarType = errBarType self.errValType = errValType self.noEndCap = noEndCap self.plus = plus self.minus = minus self.val = val self.spPr = spPr