Excel 365 comments ("threaded comments") are no longer visible in Excel after openpyxl save
Excel 365 appears to have changed how comments work. Old-style comments are now called "notes", and a new threaded system is used for comments. Both comment styles can be accessed through the existing openpyxl comments API, but Excel does not show new-style comments after openpyxl writes a spreadsheet containing them.
Here's a screenshot showing the two types of comments. The left box is a new-style comment on A1, and the right box is an old-style comment, a.k.a. a note, on A2.
openpyxl can read these comments mostly fine, modulo some extra text Excel appears to insert:
Python 3.9.1 (default, Dec 28 2020, 11:24:06)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from openpyxl import load_workbook
In [2]: path = '/Volumes/[C] Boot Camp/Users/awang/Desktop/comment-test.xlsx'
In [3]: wb = load_workbook(path)
In [4]: ws = wb.active
In [5]: ws['A1'].comment
Out[5]:
Comment: [Threaded comment]
Your version of Excel allows you to read this threaded comment; however, any edits to it will get removed if the file is opened in a newer version of Excel. Learn more: https://go.microsoft.com/fwlink/?linkid=870924
Comment:
New-style comment 1
Reply:
New-style comment reply 1
Reply:
New-style comment reply 2 by tc={1BE17AE2-716D-4EAC-BC59-7BFECFA1DFF3}
However, after saving, the new-style comment appears to disappear from Excel:
openpyxl can still read the comment text:
# continued from earlier
In [6]: wb.save(path)
In [7]: wb2 = load_workbook(path)
In [8]: ws2 = wb2.active
In [9]: ws2['A1'].comment
Out[9]:
Comment: [Threaded comment]
Your version of Excel allows you to read this threaded comment; however, any edits to it will get removed if the file is opened in a newer version of Excel. Learn more: https://go.microsoft.com/fwlink/?linkid=870924
Comment:
New-style comment 1
Reply:
New-style comment reply 1
Reply:
New-style comment reply 2 by tc={1BE17AE2-716D-4EAC-BC59-7BFECFA1DFF3}
In [10]: ws2['A2'].comment
Out[10]:
Comment: awang:
Old-style comment by awang
So the information still appears to be in there somewhere, but perhaps in a form that Excel doesn't like?