### 本文仅作笔记之用
B3~F3为输入值,G3为公式计算值
第一次读取,代码如下
import openpyxl
book = openpyxl.load_workbook(r"E:\Fan\Python\20210810.xlsx")
wb = book.active
g3_value = wb.cell(3, 7).value
print(g3_value)
结果如下:
C:\Users\FAN\AppData\Local\Programs\Python\Python39\python.exe E:/Fan/Python/Program/20210810.py
=SUM(B3:F3)
Process finished with exit code 0
可见,只是读取了G3中的公式,并未读取到值
在openpyxl中加上data_only=True
import openpyxl
book = openpyxl.load_workbook(r"E:\Fan\Python\20210810.xlsx", data_only=True)
wb = book.active
g3_value = wb.cell(3, 7).value
print(g3_value)
结果如下
C:\Users\FAN\AppData\Local\Programs\Python\Python39\python.exe E:/Fan/Python/Program/20210810.py
44
Process finished with exit code 0
成功读取值