Openpyxl 1.8.5: Reading the result of a formula typed in a cell using openpyxl

后端 未结 4 705
刺人心
刺人心 2020-11-30 11:21

I am printing some formula in one of the Excel sheets:

wsOld.cell(row = 1, column = 1).value = \"=B3=B4\"

But I cannot use its result in im

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 11:59

    I have solved the matter using a combination of openpyxl and pandas:

    import pandas as pd
    import openpyxl
    from openpyxl import Workbook , load_workbook
    
    
    source_file = "Test.xlsx"
    # write to file
    wb = load_workbook (source_file)
    ws = wb.active
    ws.title = "hello world"
    ws.append ([10,10])
    wb.save(source_file)
    
    # read from file
    df = pd.read_excel(source_file)
    sum_jan = df ["Jan"].sum() 
    print (sum_jan)
    

提交回复
热议问题