Python can’t accept formula with space in it.

Like this the ‘original data’ sheet

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula('IF(Original Data!B4<>"",Original Data!B4,"")'), center)
```

it will show error

if i use this

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula('IF('Original Data'!B4<>"",'Original Data'!B4,"")'), center)
```

it also show error

if i use this

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula("IF('Original Data'!B4<>"",'Original Data'!B4,"")"), center)
```

it also error

Is there a way to run the formula? I’ll try any suggestion. Thanks

You need to either escape the quotes in the string or else use triple quotes at the outer level like this:

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula("""IF('Original Data'!B4<>"",'Original Data'!B4,"")"""), center)
```

See the Python docs about strings, quotes and escaping.

### Answer：

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula('IF(Original Data!B4<>"",Original Data!B4,"")'), center)
```

error

```
raise ExcelFormulaParser.FormulaParseException, "can't parse formula " + s
FormulaParseException: can't parse formula IF(Original data!B3<>"";Original data!B3;"")
```

next

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula('IF('Original Data'!B4<>"",'Original Data'!B4,"")'), center)
```

error

next

```
sheet.write_merge(0, 0, 5, 8, xlwt.Formula("IF('Original Data'!B4<>"",'Original Data'!B4,"")"), center)
```

error

```
raise ExcelFormulaParser.FormulaParseException, "can't parse formula " + s
FormulaParseException: can't parse formula IF('Original data'!B3<>;'Original data'!B3;)
```

Tags: excel, pythonpython