在 MacOS 上使用 xlwings python 删除 Excel 工作表中的所有注释?

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

我正在寻找一种使用 python 删除 Excel 工作表中所有注释的方法。

在 Windows 上,我可以使用以下命令来执行此操作:

ws2.used_range.api.ClearComments()

但这在 Mac 上不起作用。

如何在 Mac 上使用 xlwings 删除 Excel 工作表中的所有注释?

python excel macos xlwings
1个回答
1
投票

在 openpyxl 中,你必须逐个单元地执行此操作。
在 Xlwings 中,您可以逐个单元格或范围进行操作。

例如,要清除某个范围内的所有单元格,请设置范围,例如“A1:B5”或者您可以选择工作表中“已用单元格”的范围;
(代码可以在 Windows 上运行,我没有 MACOS PC)

import xlwings as xw

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

### Clear comments from all cells in range A1:B5
ws.range('A1:B5').api.ClearComments()
### Clear comments from all 'used cells' on the sheet
ws.used_range.api.ClearComments()

...

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