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.
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