相關鏈接:https://openpyxl.readthedocs.io/en/stable/index.html
https://blog.csdn.net/weixin_38883338/article/details/98733734
from openpyxl import load_workbook from openpyxl.comments import Comment commonts = """這是批注的內容""" # 注意:openpyxl 模塊不支持.xls格式的表格文件,需要重新保存為.xlsx格式的表格才行 def add_excel_comment(): file = "./xxx信息表.xlsx" wb = load_workbook(filename=file) # wb.get_sheet_by_name("xxx開發提供表") print(wb.sheetnames) ws = wb["xxx開發提供表"] # ws = wb.active 當前使用的sheet,一般都是第一頁 comment = Comment(commonts, 'author') # 設置批注框的寬,高 comment.width = 800 comment.height = 600 # 在指定的單元格上面設置批注 ws['C16'].comment = comment wb.save('./批注的內容是啥.xlsx')