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