Python添加excel表格的批注


相关链接: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')

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM