How to Retain Excel Formula when running script on it

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?

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.


Need Your Help

System.Transactions.Diagnostics.DiagnosticTrace throwing TypeInitializationException

.net .net-4.0 c++-cli windows-8

Seems related to Strange exception coming out of OdbcConnection.Open() but I'm not sure.

How to programmatically Paste CSV text into Excel and not just go into one cell? (C++)

c++ excel clipboard

I have a list/grid in an MFC (c++) application. I would like the user to be able to copy and paste the data into a spreadsheet.