How can I see the formulas of an excel spreadsheet in pandas / python?

前端 未结 3 1239
长情又很酷
长情又很酷 2020-11-28 15:05

I would like to read in an excel spreadsheet to python / pandas, but have the formulae instead of the cell results.

For example, if cell A1 is 25, and cell B1 is =A1

3条回答
  •  感动是毒
    2020-11-28 15:54

    Actually, it is doable. You currently have something like this

    import pandas as pd
    import numpy as np
    a2_value = "=A1"
    data = [1, "=A1", 3, 4]
    s = pd.Series(list(data))
    writer = pd.ExcelWriter('output.xlsx')
    s.to_excel(writer, 'Sheet1', header=False, index=False)
    writer.save()
    

    What you can do is actually this:

    import pandas as pd
    import numpy as np
    data = [1, '=CONCATENATE("=A1", '')', 3, 4]
    s = pd.Series(list(data))
    writer = pd.ExcelWriter('output.xlsx')
    s.to_excel(writer, 'Sheet1', header=False, index=False)
    writer.save()
    

    That's as well formula, but =A1 will be visible instead of its value.

提交回复
热议问题