Comments are lost when loading existing xlsx files then saving
Description
Comments are being lost when I load an existing file and save it, without any modifications.
Versions tested
- 3.1.2
- 3.0.10
Test code
import openpyxl
print(openpyxl.__version__)
def run():
input_path = "./comment-test-input.xlsx"
output_path = "./comment-test-output.xlsx"
wb = openpyxl.load_workbook(filename=input_path)
wb.save(output_path)
run()
Test file
Output file
Additional info
I am not sure if this is of any relevance, but when I filter for the xml
files containing either of the strings, "comment" or "Comment", I see that there have been files "lost" from the input file and files "added" to the output file.
Running the following code snippet:
from zipfile import ZipFile
import openpyxl
print(openpyxl.__version__)
def run():
input_path = "./comment-test-input.xlsx"
output_path = "./comment-test-output.xlsx"
wb = openpyxl.load_workbook(filename=input_path)
wb.save(output_path)
list_comment_xml_filenames(input_path, "input_file")
list_comment_xml_filenames(output_path, "output_file")
def list_comment_xml_filenames(filepath, id):
with ZipFile(filepath) as xlsx_file:
filenames = xlsx_file.namelist()
comment_filenames = filter(
lambda filename: "comment" in filename or "Comment" in filename,
filenames
)
print(f"{id}: {list(comment_filenames)}")
run()
Produces:
input_file: ['xl/comments1.xml', 'xl/threadedComments/threadedComment1.xml']
output_file: ['xl/comments/comment1.xml', 'xl/drawings/commentsDrawing1.vml']