"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Get the Raw Value of a Cell in Openpyxl Even If It Contains a Formula?

How to Get the Raw Value of a Cell in Openpyxl Even If It Contains a Formula?

Published on 2024-11-09
Browse:784

How to Get the Raw Value of a Cell in Openpyxl Even If It Contains a Formula?

How to Retrieve Actual Cell Value in Openpyxl

When accessing cell values in Excel using openpyxl, you may encounter discrepancies between the displayed value and the actual value stored in the cell if the cell contains a formula. This is because openpyxl normally interprets the formula and retrieves the calculated result.

To retrieve the actual cell value, including formulas, you can use the data_only parameter when loading the workbook. This parameter instructs openpyxl to disregard any formulas and retrieve the uncalculated cell values.

wb = openpyxl.load_workbook(filename, data_only=True)

By setting data_only to True, you can retrieve the actual cell values even for cells containing formulas. This ensures that you always have access to the underlying values, regardless of any calculations that may have been applied.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3