如何使用 excel openpyxl python 仅获取公式的输出

How to get only the output of a formula with excel openpyxl python

我的代码是:

import openpyxl
wb = openpyxl.load_workbook('C:\xampp\htdocs\dad_app\template\template.xlsm')
sheet = wb.get_active_sheet()
sheet = wb.active
sheet['A1:AP701'] = sheet['A1:AP701'].internal_value

但它也保存了公式。 如何删除公式并只获得输出?

您可以将 data_only=True 作为参数传递给 load_workbook。它将 return 上次存储的值 Excel 读取 sheet.

文档:Here

wb = openpyxl.load_workbook('C:\xampp\htdocs\dad_app\template\template.xlsm', data_only=True)