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!
Have you read the answer that you got when you asked the same question on the python-excel google-group?
(1) Lose the
=… compare with yourSUM()results.(2) The XLS format doesn’t support the
COUNTIFSfunction, which was introduced in Excel 2007.No, the formula preceded by a
=so the Excel knows you mean formula instead of text does work, with Excel 2007 or later and you didn’t try to Save As Excel 97-2003 Workbook (*.xls), which doesn’t work.