import xlwings as xw
app = xw.App(visible=True, add_book=False) # 创建一个不可见的Excel应用程序实例
wb = app.books.open(r'E:\公式.xlsx') # 打开Excel文件
sheet = wb.sheets['DC'] # 修改为你的工作表名称
# 假设需要清除公式的范围是A1到B10range_to_clear = sheet.range('A1:L50')# 清除公式但保留数值
range_to_clear.formula = range_to_clear.value# 或用以下的方法处理
for cell in range_to_clear:cell.value = cell.value