xlwt: 'CommonToken' object has no attribute 'txt'

I have written a script for generating reports in Excel using xlwt. It usually works just fine but every now and then I get this error:

Traceback (most recent call last):
  File "...\report.py", line 339, in <module>
    pa.write_row([Formula('{0} - {1}'.format(my_data[i], rowcol_to_cell(marker_top, i+2))) for i in xrange(rng)], 2, rownum1-rownum2, style=pa_data2)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormula.py", line 17, in __init__
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 87, in formula
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 94, in expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 139, in prec0_expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 157, in prec1_expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 187, in prec2_expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 216, in prec3_expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 234, in prec4_expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 257, in prec5_expr
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 492, in primary
    raise Exception("[formula] found unexpected NAME token (%r)" % name_tok.txt)

AttributeError: 'CommonToken' object has no attribute 'txt'

pa is an instance of a class I made for convenience whose methods are simply shortcuts for common xlwt actions. rowcol_to_cell is xlwt.Utils.rowcol_to_cell.

In this case, the formula being written is in the form float - cell reference, and my_data is a pandas.Series().

As I said above, 99% of the time this works just fine, but when it decides not to work only restarting my computer seems to fix it (which is really annoying!). Can anybody shed some light on this? Thank you.


Just restarted my computer and I'm still having this issue. Which means that I have no idea how I fixed this in the past.


I got a similar error when trying to add a VLOOKUP formula. It turned to be an error in the formula i was trying to add. I figured out the formula error by trying it manually in an excel sheet. After fixing the forumula the xlwt error went away.

Need Your Help

Best method for Flex to PHP communication?

php xml flex amfphp weborb

What is the best method for communication between Flex and PHP?

beforeSend jquery ajax

jquery ajax authentication

I am making a simple login for my website and I am using ajax to interact with database. I wanted to make it a bit safe so I search for security for ajax so I search for AJAX authentication and rea...