Parse error using SUMIF in xlwt.Formula

450 views
Skip to first unread message

Andrew H

unread,
Mar 15, 2014, 1:28:12 AM3/15/14
to python...@googlegroups.com
I have this in my code:

     import xlwt
     ...
     sumformula = 'SUMIF(E:E;"Foo";F:F)'
     ws.write(2, 13, xlwt.Formula(sumformula))

I can't seem to get that to work.  I suspect it's a limitation in the .xls format (as opposed to .xlsx) but I'm not sure.  Something simpler works, such as SUM(), but not what I have.  When I try to use it, I get:

Traceback (most recent call last):
  File "./createmultiples.py", line 37, in <module>
    ws.write(2, 13, xlwt.Formula(sumformula))
  File "/usr/lib/python2.6/site-packages/xlwt/ExcelFormula.py", line 22, in __init__
    raise ExcelFormulaParser.FormulaParseException, "can't parse formula " + s
xlwt.ExcelFormulaParser.FormulaParseException: can't parse formula SUMIF(E:E;"Foo";F:F)

Am I out of luck on this, or am I missing something?  Thanks in advance.

John Machin

unread,
Mar 15, 2014, 5:26:59 AM3/15/14
to python...@googlegroups.com


On Saturday, March 15, 2014 4:28:12 PM UTC+11, Andrew H wrote:
I have this in my code:

     import xlwt
     ...
     sumformula = 'SUMIF(E:E;"Foo";F:F)'
     ws.write(2, 13, xlwt.Formula(sumformula))

I can't seem to get that to work.  I suspect it's a limitation in the .xls format (as opposed to .xlsx) but I'm not sure.  Something simpler works, such as SUM(), but not what I have.  When I try to use it, I get:

It's a known deficiency in the xlwt formula parser.
Workaround:
xlwt.Formula('SUMIF(E1:E65536;"Foo";F1:F65536)')

What did you try with SUM() that worked? SUM(E:E) doesn't work.
 

Andrew H

unread,
Mar 15, 2014, 1:24:41 PM3/15/14
to python...@googlegroups.com
My sum was not over a complete column.  It was something like =SUM(F5:F7).  Very simple.

Andrew H

unread,
Mar 15, 2014, 1:33:59 PM3/15/14
to python...@googlegroups.com
This suggestion worked perfectly.  Thank you very much.
Reply all
Reply to author
Forward
0 new messages