使用Python删除Excel工作表中的所有注释?

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

我想使用 python 删除 Excel 工作表中的所有注释 -

目前我可以使用以下方法逐个单元地执行此操作:

ws[wCell].note.delete()     # for Mac
ws.range(wCell).api.Comment.Delete()     # for Windows

是否可以以某种方式删除在 Windows 和 Mac 上工作的 Excel 工作表中的所有注释? (每个 python 模块,如 xlwings 或 openpyxl 都会非常受欢迎)

python excel openpyxl xlwings
1个回答
0
投票

在 openpyxl 中你必须这样做

cell by cell

在 Xlwings 中,您可以执行
cell by cell
range

例如对于从 A1 到 B5 的所有单元格;

import xlwings as xw

wb = xw.Book('foo.xlsx')
ws = wb.sheets["Sheet1"]

ws.range('A1:B5').api.ClearComments()
...

© www.soinside.com 2019 - 2024. All rights reserved.