Formula Parse Error

544 views
Skip to first unread message

Kevin Lamb

unread,
Feb 10, 2012, 5:20:01 PM2/10/12
to python-excel
I am running into a parse error while using xlwt. Simple formula's
like SUM() work fine but I tried to run this slight more complex
formula and received the following error.

xlwt.ExcelFormulaParser.FormulaParseException: can't parse formula
=COUNTIFS(hospital_data!C1:C6500,LEFT(B1,4),hospital_data!
D1:D65000,RIGHT(B1,1),hospital_data!F1:F65000,A3)

This is the code I am attempting to run.

hospital_count_formula = '=COUNTIFS(hospital_data!C1:C6500,LEFT({0},
4),hospital_data!D1:D65000,RIGHT({0},1),hospital_data!F1:F65000,
{1})'.format(quarter_ref, state_ref)

sheet_overview.write(row, column, Formula(hospital_count_formula))

I have tried using a defined numerical range (A1:A5000) instead of
(A:A) and I have also tried simply passing this through as a string
but it is not evaluated in Excel.

This formula does work when copy and pasted into Excel. Any thoughts
would be most appreciated.

Thank you!

Kevin

John Machin

unread,
Feb 10, 2012, 6:07:04 PM2/10/12
to python...@googlegroups.com
Things to do to get yourself back on the road faster than by asking questions here:

(1) compare the start of your working SUM formulas with the start of your problematical COUNTIFS non-formula

(2) have a quick look in this group to see if the problem has been mentioned already (e.g. topic "conditional formulas" last month appears relevant)

Craig Barnes

unread,
Feb 10, 2012, 6:38:42 PM2/10/12
to python...@googlegroups.com
no = needed :)

> --
> You received this message because you are subscribed to the Google Groups
> "python-excel" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/python-excel/-/rfTZoRVxJ2MJ.
>
> To post to this group, send an email to python...@googlegroups.com.
> To unsubscribe from this group, send email to
> python-excel...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/python-excel?hl=en-GB.

--
Craig

()  ascii ribbon campaign - against html mail
/\

John Machin

unread,
Feb 10, 2012, 6:49:43 PM2/10/12
to python...@googlegroups.com
and in any case COUNTIFS() is not available in XLS files. To see this for yourself, fire up Excel 2007 or later, enter a formula with COUNTIFS in it, and try to Save As Excel 97-2003 Workbook (*.xls)

If the users are not allowed to modify the workbook that you are creating, you could avoid formulas and calculate the results in Python
Reply all
Reply to author
Forward
0 new messages