Expr
Excel formula expressions built from Python operators.
Every node is a str subclass whose string value is the finished, =-prefixed
formula, so an expression can be assigned straight to an openpyxl cell::
ws["B5"] = cell("B3") - cell("B4") # cell gets "=B3-B4"
Nesting uses :attr:Expr.text (the body, without the =) rather than the string
value. That distinction is the one invariant holding the whole module together.
BinOp
Bases: Expr
A binary operation between two expressions.
Source code in src/pycountant/excel/expr.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
Expr
Bases: str
Base class for every formula fragment.
The str value is the complete formula ("=B3-B4"); :attr:text is the
body ("B3-B4"). Composition always reads :attr:text.
Source code in src/pycountant/excel/expr.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
formula
property
The complete formula as a plain str, including the leading =.
text
property
The formula body, without the leading =.
pct()
Postfix percent: x.pct() renders x%.
Source code in src/pycountant/excel/expr.py
158 159 160 | |
shift(rows=0, cols=0)
Return a copy with every relative reference moved by rows/cols.
Absolute ($-locked) components are left alone. Nodes without references
return themselves.
Source code in src/pycountant/excel/expr.py
98 99 100 101 102 103 104 | |
Lit
Bases: Expr
A Python value rendered as an Excel literal.
Source code in src/pycountant/excel/expr.py
189 190 191 192 193 194 195 196 197 198 | |
Raw
Bases: Expr
Verbatim formula text.
Parenthesised whenever it is nested, because its internal structure is unknown
and Raw("A1+B1") * 2 must not silently become A1+B1*2. Pass
atomic=True when the text is a single self-contained term.
Source code in src/pycountant/excel/expr.py
230 231 232 233 234 235 236 237 238 239 | |
UnaryOp
Bases: Expr
A prefix (-) or postfix (%) operation.
Source code in src/pycountant/excel/expr.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
lit(value)
Coerce a Python value into an :class:Expr, passing existing ones through.
Source code in src/pycountant/excel/expr.py
184 185 186 | |