I have work with xlsxwriter and I try to print simple formula with a print of formula into the sheet
import xlsxwriter
workbook = xlsxwriter.Workbook('filename1.xlsx')
format_val=workbook.add_format()
worksheet = workbook.add_worksheet()
worksheet.write(0,1,5)
worksheet.write(1,1,2)
worksheet.write_formula(3,0, '=SUM(B1:B2)')
workbook.close()
csvf = StringIO(import_file.read().decode())
Here the Image of how to show and when I press = than output is print 7
But output also will be Zero (0). I know 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.
I have tried this. It is working for me but it's not a proper thing when I try with Upper Case is not working: ~
num_formate=format_val.set_num_format('0')
worksheet.write_formula(5,1, '=2+1',num_formate,4)
But when it's open How to show calculate value?
Passing empty string to value arg works for me.
# # xlsxwriter/worksheet.py
#
# class Worksheet(xmlwriter.XMLwriter):
# ...
# def write_formula(self, row, col, formula, cell_format=None, value=0)
worksheet.write_formula(3, 0, '=SUM(B1:B2)', None, '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With