[Python] How to view certain cell's value (not formula), while data_only=False? openpyxl,...

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    Using the following code, how can I take a value (not the formula) from an excel file's cell to another excel file's cell while maintaining data_only = False?

    from openpyxl import load_workbook
    import openpyxl
    #load excel file
    counter = 0
    workbook_process = load_workbook(filename="file.xlsx", data_only = False)
    sheets_process = workbook_process.sheetnames
    sheets_process_parameters = workbook_process[sheets_process[1]]
    sheets_process_output = workbook_process[sheets_process[7]]

    workbook_data_streaming = load_workbook(filename="file2.xlsx", data_only = True)
    sheets_workbook_data_streaming = workbook_data_streaming.sheetnames
    sheet_data_streaming = workbook_data_streaming[sheets_workbook_data_streaming[1]]



    sheet_data_streaming.cell(row=5, column=34).value = sheets_process_output["G57"].value

    workbook_data_streaming.save(filename="Process1.xlsx")


    The problem is that the following line

    sheet_data_streaming.cell(row=5, column=34).value = sheets_process_output["G57"].value


    is assigning a formula to sheet_data_streaming.cell(row=5, column=34).value, not the value calculated in sheets_process_output.

    Continue reading...

Compartilhe esta Página