【发布时间】:2019-03-24 08:27:56
【问题描述】:
我正在使用 Python 2.7,我尝试执行 here 的操作(使用 Python 将 cmets 添加到 excel 文件工作表中),但这不起作用...
这是我的代码:
import os, sys, shutil, time, openpyxl
from openpyxl import Workbook
from openpyxl.comments import Comment
...
path = 'K:/....../data.xlsx'
wb = Workbook()
ws = wb.active
...
comment = ws["A1"].comment
comment = Comment('This is the comment text', 'Comment Author')
...
wb.save(path)
我也试过了:
comment = Comment('This is the comment text', 'Comment Author')
ws["A1"].comment = comment
但这是否会创建我的 xlsx 文件而没有对“A1”单元格进行注释,这是否告诉我“TypeError:预期类型 'unicode'”和“引发 TypeError('expected ' + str(expected_type))”。
你能帮我解决这个问题吗?谢谢
注意:我也试过this,但它说“没有属性AddComment”......
【问题讨论】:
标签: python excel python-2.7 openpyxl