Writing formula using Xlsxwriter in python

Viewed 163

I have this statement

worksheet.write_formula(j + 3, 5, f'=IF({xl_rowcol_to_cell(j + 3,4)}>=90,, " Exce")')

I want to write a formula in excel to compare the value of cell(j + 3, 5) if its value

  • 90 write Excellent
  • 80 write v. good
  • 70 write good

i.e. examined cell value

1 Answers

What you need are nested IFs, like:

worksheet.write_formula(j + 3, 5, f'=IF({xl_rowcol_to_cell(j + 3,4)}>=90;"Excellent";IF({xl_rowcol_to_cell(j + 3,4)}>=80;"Very Good";IF({xl_rowcol_to_cell(j + 3,4)}>=70;"Good";"")))')

Bear in mind that:

XlsxWriter doesn’t calculate the result of a formula and instead stores the value 0 as the formula result. It then sets a global flag in the XLSX file to say that all formulas and functions should be recalculated when the file is opened.

As per the documentation: https://xlsxwriter.readthedocs.io/working_with_formulas.html

Related