Home >Backend Development >Python Tutorial >How to Get the Raw Value of a Cell in Openpyxl Even If It Contains a Formula?
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.
<code class="python">wb = openpyxl.load_workbook(filename, data_only=True)</code>
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.
The above is the detailed content of How to Get the Raw Value of a Cell in Openpyxl Even If It Contains a Formula?. For more information, please follow other related articles on the PHP Chinese website!