I'm trying to create an Excel file with a simple formula:
import xlsxwriter
workbook = xlsxwriter.Workbook('testxlsx.xlsx', {'strings_to_numbers': True})
ws = workbook.add_worksheet()
ws.write('A2', 'Number one')
ws.write('B2', '1')
ws.write('A3', 'Number two')
ws.write('B3', "1000")
ws.write('A4', "Number three")
ws.write('B4', "1050")
ws.write('A5', "Number four")
ws.write('B5', "3")
ws.write('A6', "Result")
ws.write('B6', '=IF(B5=3,ROUND(100-(B3/B4*100),1),ROUND(100-(B3/(B4*1.502)*100),1))')
workbook.close()
The generated file works perfectly in Excel, but when opened in LibreOffice Calc the formula is not evaluated. I need to reenter the numeric values and then it works.
What am I doing wrong?
xlsxwriter
-link it also mentions that we can include the calculated result of the formula (if we have it) as the 5th argument to.write()
and store it in the worksheet. – Carinthia