I am using the write_formula method from Xlsxwriter module in Python to calculate some values. However what I have noticed is that I have to write per cell. As the method does not accept a range of cells.
What I want to achieve is to be able to have the formula stored for all the rows in the specific column, this includes rows where there is no data as well, so for example the whole excel range (2: 1048546).
At the moment I have achieved this by looping through a range like so:
for i in range(2, 1048546):
str_i = f"A{i}"
formula = "=SUM(1, 2)"
worksheet.write_formula(f"B{i}", formula=formula, value=0)
But as mentioned I would like to do it for the whole column, so I can skip the time consuming for loop. I did something similar using the data_validation method like so:
worksheet.data_validation(
"L2:L1048546",
{"validate": "list", "source": ["value1", "value2"]},
)
But the data_validation accepts the range of values unlike the write_formula method. I also tried it with the range for the write_formula method like so:
worksheet.write_formula(
"H2:H1048546",
"SUM(1, 2)",
value=0
)
But this only wrote the data for where rows have values.
Is there another way to get the write_formula to work the same way data_validation works?