当前位置:   article > 正文

Python使用openpyxl插入excel批注,修改批注_openpyxl 可以操作表格寫入批註嗎?

openpyxl 可以操作表格寫入批註嗎?

一、openpyxl插入批注

  1. from openpyxl import Workbook
  2. from openpyxl.comments import Comment
  3. if __name__ == '__main__':
  4. wb = Workbook()
  5. ws = wb.active
  6. comment = Comment('hello comment', 'yunan')
  7. comment.width = 200
  8. comment.height = 40
  9. ws['A1'].comment = comment
  10. wb.save('test.xlsx')

二、修改批注

  1. from openpyxl import load_workbook
  2. from openpyxl.comments import Comment
  3. file = 'C:\yunan\\test.xlsx'
  4. if __name__ == '__main__':
  5. wb = load_workbook(filename=file)
  6. ws = wb.active
  7. comment = Comment('hello world', 'yunan')
  8. ws['A1'].comment = comment
  9. wb.save(file)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/907518
推荐阅读
相关标签
  

闽ICP备14008679号