如何使用 python 从 excel 单元格中删除公式?

问题描述 投票:0回答:1

如何使用 python 从 excel 单元格中删除公式 =SUM(A1:A10)?

python excel xlwings
1个回答
0
投票

您可以重新评估该值以删除公式。

import xlwings as xw

wb = xw.Book('your_book.xlsx')
sh =wb.sheets[0]
# Calculate the sum of cells A1:A10
sum_formula = '=SUM(A1:A10)'

# Set the value of cell A11 to the calculated sum
sh.range('A11').value = sum_formula
# Get the value and reassing it
val=sh.range('A11').value 
sh.range('A11').value = val
#Set the financial format
sh.range('A11').number_format = '$#,##0.00'
© www.soinside.com 2019 - 2024. All rights reserved.