如何使用 python 从 excel 单元格中删除公式 =SUM(A1:A10)?
您可以重新评估该值以删除公式。
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'