airween
airween

Reputation: 6193

Python xlwt can't parse "complex" formula, reference to another worksheet

I would like to put a formula to an Excel cell:

write(
  rownr,
  colnr,
  xlwt.Formula("ROUND(SUM('Hungarian word'.G%d:'Hungarian word'!G%d);0)" % (intval[0], intval[1]))

(Note: the 'Hungarian word' is more word with special chars, so the type of name of worksheet is unicode)

When I run this code, I get this error:

xlwt.ExcelFormulaParser.FormulaParseException: can't parse formula ROUND(SUM('Hungarian word'.G2:'Hungarian word'.G3);0)

I've tried to replace the "." characters to "!", but I got same error:

xlwt.ExcelFormulaParser.FormulaParseException: can't parse formula ROUND(SUM('Hungarian word'!G2:'Hungarian word'!G3);0)

If I put the formula as string to cell:

write(
  rownr,
  colnr,
  "=KEREK(SZUM('Hungarian word'.G%d:'Hungarian word'.G%d);0)" % (intval[0], intval[1]))

then it works, but I'm afraid then works only in correct localized version of Excel.

What is the expected way to put a rounded cumulated value of many cells from another worksheet?

Upvotes: 0

Views: 1027

Answers (1)

airween
airween

Reputation: 6193

Ok, here is the solution:

xlwt.Formula("ROUND(SUM('%s'!$G$%d:$G$%d);0)" % (u"Hungarian word", intval[0], intval[1])))

which produced the expected formula,

sorry for the noise :)

a.

Upvotes: 1

Related Questions