@@ -287,6 +287,7 @@ def _literal():
287
287
_is_decimal = isinstance (content , decimal .Decimal ),
288
288
)
289
289
290
+ pkdc ("{}!{}={}" , cell .sheet .title , cell .xl_id , content )
290
291
self .is_formula = isinstance (content , (list , tuple ))
291
292
if self .is_formula :
292
293
_formula ()
@@ -300,6 +301,8 @@ def is_decimal(self):
300
301
def py_value (self ):
301
302
if (rv := self .get ("_py_value" )) is None :
302
303
self ._error ("expected an expression with a single value expr={}" , self )
304
+ if callable (rv ):
305
+ self ._py_value = rv = rv ()
303
306
if not isinstance (rv , (bool , str , decimal .Decimal )):
304
307
self ._error ("unexpected expression value={} expr={}" , rv , self )
305
308
return rv
@@ -393,7 +396,7 @@ def _xl_id(cell):
393
396
self .pkupdate (
394
397
_link_ref = content ,
395
398
_is_decimal = l .expr .is_decimal (),
396
- _py_value = l .expr .py_value () if c .resolved_count == 1 else None ,
399
+ _py_value = ( lambda : l .expr .py_value () ) if c .resolved_count == 1 else None ,
397
400
_xl_formula = _xl_formula (c .pairs ),
398
401
cells = c .cells ,
399
402
resolved_count = c .resolved_count ,
@@ -525,21 +528,23 @@ def init(cls):
525
528
def _bool (token , func ):
526
529
cls (token , func , _is_decimal = False , _infix = True )
527
530
528
- def _multi (token , func , init , xl ):
531
+ def _multi (token , func , init = None , xl = None ):
529
532
cls (
530
533
token ,
531
534
"multi" ,
532
535
_py_func_multi_func = func ,
533
- _py_func_multi_init = decimal .Decimal (init ),
534
- _xl_func = xl ,
536
+ _py_func_multi_init = None if init is None else decimal .Decimal (init ),
537
+ _xl_func = xl or token ,
535
538
operand_count = (1 , 65535 ),
536
539
_is_multi = True ,
537
540
_is_decimal = True ,
538
541
)
539
542
540
543
cls ("%" , lambda x , y : x % y , _xl_func = "MOD" , _is_decimal = True )
541
- _multi ("*" , lambda x , y : x * y , 1 , "PRODUCT" )
542
- _multi ("+" , lambda x , y : x + y , 0 , "SUM" )
544
+ _multi ("*" , lambda rv , y : rv * y , 1 , "PRODUCT" )
545
+ _multi ("+" , lambda rv , y : rv + y , 0 , "SUM" )
546
+ _multi ("MAX" , max )
547
+ _multi ("MIN" , min )
543
548
cls (
544
549
"-" ,
545
550
"minus" ,
@@ -570,7 +575,7 @@ def evaluate(self, operands, cell):
570
575
),
571
576
_op_spec = self ,
572
577
_operands = o ,
573
- _py_value = self ._py_func (o ),
578
+ _py_value = lambda : self ._py_func (o ),
574
579
_xl_formula = self ._xl_func (o ),
575
580
resolved_count = 1 ,
576
581
)
@@ -646,7 +651,7 @@ def _iter():
646
651
self ._error (
647
652
"not decimal operand type={} value={} operand={}" , type (v ), v , e
648
653
)
649
- rv = self ._py_func_multi_func (rv , v )
654
+ rv = v if rv is None else self ._py_func_multi_func (rv , v )
650
655
return rv
651
656
652
657
def _xl_func_default (self , operands ):
@@ -766,6 +771,10 @@ def __init__(self, cfg):
766
771
super ().__init__ (cfg )
767
772
self .tables = []
768
773
774
+ def blank_table (self ):
775
+ """Create a table with one row, which is blank"""
776
+ self .table (title = f"blank_table-{ len (self .tables )} " ).row ()
777
+
769
778
def table (self , ** kwargs ):
770
779
"""Appends table to sheets
771
780
0 commit comments