class Text(Serialisable): tagname = "s" tpls = Sequence(expected_type=TupleList) x = Sequence(expected_type=Index) v = String() u = Bool(allow_none=True) f = Bool(allow_none=True) c = String(allow_none=True) cp = Integer(allow_none=True) _in = Integer(allow_none=True) bc = HexBinary(allow_none=True) fc = HexBinary(allow_none=True) i = Bool(allow_none=True) un = Bool(allow_none=True) st = Bool(allow_none=True) b = Bool(allow_none=True) __elements__ = ('tpls', 'x') def __init__( self, tpls=(), x=(), v=None, u=None, f=None, c=None, cp=None, _in=None, bc=None, fc=None, i=None, un=None, st=None, b=None, ): self.tpls = tpls self.x = x self.v = v self.u = u self.f = f self.c = c self.cp = cp self._in = _in self.bc = bc self.fc = fc self.i = i self.un = un self.st = st self.b = b
class TablePartList(Serialisable): tagname = "tableParts" count = Integer(allow_none=True) tablePart = Sequence(expected_type=Related) __elements__ = ('tablePart', ) __attrs__ = ('count', ) def __init__( self, count=None, tablePart=(), ): self.tablePart = tablePart def append(self, part): self.tablePart.append(part) @property def count(self): return len(self.tablePart) def __bool__(self): return bool(self.tablePart) __nonzero__ = __bool__
class TableStyleList(Serialisable): tagname = "tableStyles" defaultTableStyle = String(allow_none=True) defaultPivotStyle = String(allow_none=True) tableStyle = Sequence(expected_type=TableStyle, allow_none=True) __elements__ = ('tableStyle', ) __attrs__ = ("count", "defaultTableStyle", "defaultPivotStyle") def __init__( self, count=None, defaultTableStyle="TableStyleMedium9", defaultPivotStyle="PivotStyleLight16", tableStyle=(), ): self.defaultTableStyle = defaultTableStyle self.defaultPivotStyle = defaultPivotStyle self.tableStyle = tableStyle @property def count(self): return len(self.tableStyle)
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 _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 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 DataLabelList(_DataLabelBase): tagname = "dLbls" dLbl = Sequence(expected_type=DataLabel, allow_none=True) delete = NestedBool(allow_none=True) numFmt = _DataLabelBase.numFmt spPr = _DataLabelBase.spPr txPr = _DataLabelBase.txPr dLblPos = _DataLabelBase.dLblPos showLegendKey = _DataLabelBase.showLegendKey showVal = _DataLabelBase.showVal showCatName = _DataLabelBase.showCatName showSerName = _DataLabelBase.showSerName showPercent = _DataLabelBase.showPercent showBubbleSize = _DataLabelBase.showBubbleSize showLeaderLines = _DataLabelBase.showLeaderLines separator = _DataLabelBase.separator extLst = _DataLabelBase.extLst __elements__ = ( "delete", "dLbl", ) + _DataLabelBase.__elements__ def __init__(self, dLbl=(), delete=None, **kw): self.dLbl = dLbl self.delete = delete super(DataLabelList, self).__init__(**kw)
class DateTimeField(Serialisable): tagname = "d" x = Sequence(expected_type=Index) v = DateTime() u = Bool(allow_none=True) f = Bool(allow_none=True) c = String(allow_none=True) cp = Integer(allow_none=True) __elements__ = ('x', ) def __init__( self, x=(), v=None, u=None, f=None, c=None, cp=None, ): self.x = x self.v = v self.u = u self.f = f self.c = c self.cp = cp
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 SortState(Serialisable): tagname = "sortState" columnSort = Bool(allow_none=True) caseSensitive = Bool(allow_none=True) sortMethod = NoneSet(values=(['stroke', 'pinYin'])) ref = CellRange() sortCondition = Sequence(expected_type=SortCondition, allow_none=True) extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('sortCondition',) def __init__(self, columnSort=None, caseSensitive=None, sortMethod=None, ref=None, sortCondition=(), extLst=None, ): self.columnSort = columnSort self.caseSensitive = caseSensitive self.sortMethod = sortMethod self.ref = ref self.sortCondition = sortCondition def __bool__(self): return self.ref is not None __nonzero__ = __bool__
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 MultiCellRange(Strict): ranges = Sequence(expected_type=CellRange) def __init__(self, ranges=()): if isinstance(ranges, str): ranges = [CellRange(r) for r in ranges.split()] self.ranges = ranges def __contains__(self, coord): for r in self.ranges: if coord in r: return True return False def __repr__(self): ranges = " ".join([str(r) for r in self.ranges]) return "<{0} [{1}]>".format(self.__class__.__name__, ranges) def __str__(self): ranges = u" ".join([str(r) for r in self.ranges]) return ranges __unicode__ = __str__ def add(self, coord): """ Add a cell coordinate. Will create a new CellRange """ if coord not in self: cr = CellRange(coord) ranges = self.ranges ranges.append(cr) self.ranges = ranges return self __iadd__ = add def __eq__(self, other): if isinstance(other, str): other = self.__class__(other) return self.ranges == other.ranges def __ne__(self, other): return not self == other def __bool__(self): return bool(self.ranges) __nonzero__ = __bool__ def remove(self, coord): if not isinstance(coord, CellRange): coord = CellRange(coord) self.ranges.remove(coord) def __iter__(self): for cr in self.ranges: yield cr
class GeomGuideList(Serialisable): gd = Sequence(expected_type=GeomGuide, allow_none=True) def __init__(self, gd=None, ): self.gd = gd
class DashStopList(Serialisable): ds = Sequence(expected_type=DashStop, allow_none=True) def __init__( self, ds=None, ): self.ds = ds
class IndexedColorList(Serialisable): rgbColor = Sequence(expected_type=RgbColor, ) __elements__ = ('rgbColor',) def __init__(self, rgbColor=(), ): self.rgbColor = rgbColor
class MRUColorList(Serialisable): color = Sequence(expected_type=Color, ) __elements__ = ('color',) def __init__(self, color=None, ): self.color = color
class AutoFilter(Serialisable): tagname = "autoFilter" ref = CellRange() filterColumn = Sequence(expected_type=FilterColumn, allow_none=True) sortState = Typed(expected_type=SortState, allow_none=True) extLst = Typed(expected_type=ExtensionList, allow_none=True) __elements__ = ('filterColumn', 'sortState') def __init__(self, ref=None, filterColumn=(), sortState=None, extLst=None, ): self.ref = ref self.filterColumn = filterColumn self.sortState = sortState def __bool__(self): return self.ref is not None __nonzero__ = __bool__ def add_filter_column(self, col_id, vals, blank=False): """ Add row filter for specified column. :param col_id: Zero-origin column id. 0 means first column. :type col_id: int :param vals: Value list to show. :type vals: str[] :param blank: Show rows that have blank cell if True (default=``False``) :type blank: bool """ self.filterColumn.append(FilterColumn(colId=col_id, vals=vals, blank=blank)) def add_sort_condition(self, ref, descending=False): """ Add sort condition for cpecified range of cells. :param ref: range of the cells (e.g. 'A2:A150') :type ref: string :param descending: Descending sort order (default=``False``) :type descending: bool """ cond = SortCondition(ref, descending) if self.sortState is None: self.sortState = SortState(ref=ref) self.sortState.sortCondition.append(cond)
class CellStyleList(Serialisable): tagname = "cellXfs" __attrs__ = ("count", ) count = Integer(allow_none=True) xf = Sequence(expected_type=CellStyle) alignment = Sequence(expected_type=Alignment) protection = Sequence(expected_type=Protection) __elements__ = ('xf', ) def __init__( self, count=None, xf=(), ): self.xf = xf @property def count(self): return len(self.xf) def __getitem__(self, idx): return self.xf[idx] def _to_array(self): """ Extract protection and alignments, convert to style array """ self.prots = IndexedList([Protection()]) self.alignments = IndexedList([Alignment()]) styles = [] # allow duplicates for xf in self.xf: style = xf.to_array() if xf.alignment is not None: style.alignmentId = self.alignments.add(xf.alignment) if xf.protection is not None: style.protectionId = self.prots.add(xf.protection) styles.append(style) return IndexedList(styles)
class AuthorList(Serialisable): tagname = "authors" author = Sequence(expected_type=unicode) authors = Alias("author") def __init__(self, author=(), ): self.author = author
class ExternalSheetDataSet(Serialisable): sheetData = Sequence(expected_type=ExternalSheetData, ) __elements__ = ('sheetData', ) def __init__( self, sheetData=None, ): self.sheetData = sheetData
class CustomChartsheetViews(Serialisable): tagname = "customSheetViews" customSheetView = Sequence(expected_type=CustomChartsheetView, allow_none=True) __elements__ = ('customSheetView',) def __init__(self, customSheetView=None, ): self.customSheetView = customSheetView
class GroupItems(Serialisable): tagname = "groupItems" m = Sequence(expected_type=Missing) n = Sequence(expected_type=Number) b = Sequence(expected_type=Boolean) e = Sequence(expected_type=Error) s = Sequence(expected_type=Text) d = Sequence(expected_type=DateTimeField,) __elements__ = ('m', 'n', 'b', 'e', 's', 'd') __attrs__ = ("count", ) def __init__(self, count=None, m=(), n=(), b=(), e=(), s=(), d=(), ): self.m = m self.n = n self.b = b self.e = e self.s = s self.d = d @property def count(self): return len(self.m + self.n + self.b + self.e + self.s + self.d)
class BandFormatList(Serialisable): tagname = "bandFmts" bandFmt = Sequence(expected_type=BandFormat, allow_none=True) __elements__ = ('bandFmt', ) def __init__( self, bandFmt=(), ): self.bandFmt = bandFmt
class SmartTagList(Serialisable): tagname = "smartTagTypes" smartTagType = Sequence(expected_type=SmartTag, allow_none=True) __elements__ = ('smartTagType', ) def __init__( self, smartTagType=(), ): self.smartTagType = smartTagType
class Text(Serialisable): tagname = "text" t = NestedText(allow_none=True, expected_type=unicode) plain = Alias("t") r = Sequence(expected_type=RichText, allow_none=True) formatted = Alias("r") rPh = Sequence(expected_type=PhoneticText, allow_none=True) phonetic = Alias("rPh") phoneticPr = Typed(expected_type=PhoneticProperties, allow_none=True) PhoneticProperties = Alias("phoneticPr") __elements__ = ('t', 'r', 'rPh', 'phoneticPr') def __init__( self, t=None, r=(), rPh=(), phoneticPr=None, ): self.t = t self.r = r self.rPh = rPh self.phoneticPr = phoneticPr @property def content(self): """ Text stripped of all formatting """ snippets = [] if self.plain is not None: snippets.append(self.plain) for block in self.formatted: if block.t is not None: snippets.append(block.t) return u"".join(snippets)
class GradientStopList(Serialisable): tagname = "gradStopLst" gs = Sequence(expected_type=GradientStop) def __init__( self, gs=None, ): if gs is None: gs = [GradientStop(), GradientStop()] self.gs = gs
class _NamedCellStyleList(Serialisable): """ Container for named cell style objects Not used in client code """ tagname = "cellStyles" count = Integer(allow_none=True) cellStyle = Sequence(expected_type=_NamedCellStyle) __attrs__ = ("count", ) def __init__( self, count=None, cellStyle=(), ): self.cellStyle = cellStyle @property def count(self): return len(self.cellStyle) @property def names(self): """ Convert to NamedStyle objects and remove duplicates. In theory the highest xfId wins but in practice they are duplicates so it doesn't matter. """ def sort_fn(v): return v.xfId styles = [] names = set() for ns in sorted(self.cellStyle, key=sort_fn): if ns.name in names: continue style = NamedStyle(name=ns.name, hidden=ns.hidden, builtinId=ns.builtinId) names.add(ns.name) style._set_index(len(styles)) # assign xfId styles.append(style) return NamedStyleList(styles)
class ColorScale(RuleType): tagname = "colorScale" color = Sequence(expected_type=Color) __elements__ = ('cfvo', 'color') def __init__(self, cfvo=None, color=None, ): self.cfvo = cfvo self.color = color
class ExternalRow(Serialisable): r = Integer() cell = Sequence(expected_type=ExternalCell) __elements__ = ('cell', ) def __init__( self, r=(), cell=None, ): self.r = r self.cell = cell