到今天為止 xlwings 還沒有插入註解的功能
去原始開發者的 Github Pull Requests
他說之前有人有建議要加入這個功能 但他還沒更新~
如果需要使用 Python 來插入註解的話 可以用我改好 forked 出來的xlwings
使用方式如下
fromxlwingsimportWorkbook, Sheet, Range, Chart
wb= Workbook(r'Excel檔案路徑')
wb=Workbook.caller()#讀取註解x= Range('A1').commentPRintx#使用xlwings插入註解Range('B5').comment=u'中文註解'
對原始的 xlwings 我做了以下更改
在 xlwings/_xlwindows.py 檔案389行後我加入了以下
defget_comment(xl_range):try:
xl_range.Comment.Text()except:return"None"defset_comment(xl_range, value):
xl_range.ClearComments()
xl_range.AddComment()
xl_range.Comment.Visible=True
value=(value).decode('utf-8')
xl_range.Comment.Text(value)
在檔案 xlwings/main.py 877行之後我加入了以下
@propertydefcomment(self):returnxlplatform.get_comment(self.xl_range)
@comment.setterdefcomment(self, value):
xlplatform.set_comment(self.xl_range, value)
會這樣更改xlwings是參考 我前篇文章 [Python學習筆記] 利用 Python在Excel 插入註解