Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Retain Excel Formula when running script on it

Tags:

python

csv

excel

I just wrote a python script that takes an input csv, and outputs a new csv that has an extra column and does some stuff to the rows in the original file. Three of the columns in the input file had formulas, but it looks like the output file just takes the value that was in those columns, not the formula.

Is there a way to write my program such that the formula is written to the output, and not simply the value that is there?

like image 625
user1590499 Avatar asked Dec 12 '25 12:12

user1590499


1 Answers

When you convert your workbook to a CSV the formulas are not saved. Displayed values are saved in CSVs, not the formulas themselves.

If you want your formulas to be saved in the CSV, you will need have the cell show the formula itself instead of the value. You can do this by adding a ' to the beginning of the cell to indicate it should be treated as text.

In other words, this issue is caused before Python even starts reading your input CSV. The issue is created when you make the CSV.

like image 137
Daniel Avatar answered Dec 15 '25 14:12

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!