python读取单元格公式计算结果,Openpyxl读取的公式结果(Python 2.7)

I am using openpyxl to read from an excel file. I am trying to read a cell whose value is calculated by a formula.

Regular reading functions returns formula script:

`wb= openpyxl.load_workbook('forecast.xlsx')`

`sheet = wb.get_sheet_by_name('Sheet3')`

`result=sheet["F6"].value`

I tried to use (data_only=True) flag like this:

wb= openpyxl.load_workbook('forecast.xlsx', data_only=True)

Result was that all formula cells turned to blanks. Only pure values remained.

Is there a way to read a cell calculated value using openpyxl?

Update:

From further reading I suspect the issue is about re-opening a file that was already modified with openpyxl. Once I open an original file, I get the values using 'data_only' flag. Once re-opening after some modification, formula cells turn to blanks.

Tried solving this by working with 2 files- so far without much success.

Anybody has a solution for this?

解决方案

wb = openpyxl.load_workbook('forecast.xlsx', data_only=True)

Will read the actual value. (From what you have posted, I think you miss a comma that separates the arguments)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值