0

i'm trying to write a formula to a series of cells by building the string. for instance i want to display the word "true" in a cell if the corresponding cell in column G contains the word "monkey" in it.

for rowi in range(totalRows):
    thisRow = str(rowi)
    functionString = r'IF(ISNUMBER(SEARCH("monkey",G'+thisRow+')),("true")

this will produce the string "IF(ISNUMBER(SEARCH("monkey",G1)),("true")" -- if i then pass that to xlwt.Formula...

    ws.write(rowi+1, 0, xlwt.Formula(functionString))

i get this error...

File "C:\Python27\Lib\site-packages\xlwt\ExcelFormula.py", line 22, in __init__
    raise ExcelFormulaParser.FormulaParseException, "can't parse formula " + s
xlwt.ExcelFormulaParser.FormulaParseException: can't parse formula IF(ISNUMBER(SEARCH("bitmap",G2)),("true")

is it possible to use this type of function with xlwt?

Brobot
  • 43
  • 1
  • 5
  • You appear to be missing a closing parenthesis... – EML Apr 15 '12 at 18:53
  • face/palm - good catch. fixing that, i realized my formula was off too -i needed the value for false required by the IF statement. – Brobot Apr 15 '12 at 19:26

1 Answers1

0

Ignoring the impossibility that you typed in monkey and G1 whereas the error message mentions bitmap and G2 ...

I suggest that you fire up Excel, select a cell, type = and paste your formula ... what happens? This check is always advisable before going public, and is available even if your internet connection is broken.

Notes:

(1) the parentheses around "true" are redundant

(2) simpler: ISNUMBER(SEARCH("bitmap",G2))

(3) Are you really expecting that a user will open the resulting XLS file and type text into column G?

John Machin
  • 81,303
  • 11
  • 141
  • 189
  • 1) i know 2)yep, that is simpler. i'm pasting this formula in a series of rows hence the +thisRow+ 3)no, was just trying to simplify the direct problem rather than explain the entire project. in this case, i want the the statement to automatically fill the cell with a string if true, a different string if false. more specifcally, this function is a series of nested IF statements checking for several scenarios. and thanks by the way for pointing out trivial non-related issues and brow-beating me 2 hours after a solution was found. helpful. – Brobot Apr 16 '12 at 16:37