def test_dump_with_comment(): from openpyxl.writer.dump_worksheet import WriteOnlyCell test_filename = _get_test_filename() wb = Workbook(optimized_write=True) ws = wb.create_sheet() user_comment = Comment(text='hello world', author='me') cell = WriteOnlyCell(ws, value="hello") cell.comment = user_comment ws.append([cell, 3.14, None]) assert user_comment in ws._comments wb.save(test_filename) wb2 = load_workbook(test_filename) ws2 = wb2[ws.title] assert ws2['A1'].comment.text == 'hello world'
def test_dump_with_comment(DumpWorksheet): ws = DumpWorksheet from openpyxl.writer.dump_worksheet import WriteOnlyCell from openpyxl.comments import Comment user_comment = Comment(text='hello world', author='me') cell = WriteOnlyCell(ws, value="hello") cell.comment = user_comment ws.append([cell]) assert user_comment in ws._comments ws.write_header() header = ws.get_temporary_file(ws._fileobj_header_name) header.write(b"<sheetData>") # well-formed XML needed ws.close() content = open(ws._fileobj_name).read() expected = """ <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <sheetPr> <outlinePr summaryRight="1" summaryBelow="1"/> </sheetPr> <dimension ref="A1:A1"/> <sheetViews> <sheetView workbookViewId="0"> <selection activeCell="A1" sqref="A1"/> </sheetView> </sheetViews> <sheetFormatPr defaultRowHeight="15" baseColWidth="10"/> <sheetData> <row r="1" spans="1:1"><c r="A1" t="s"><v>0</v></c></row> </sheetData> <legacyDrawing r:id="commentsvml"></legacyDrawing> </worksheet> """ diff = compare_xml(content, expected) assert diff is None, diff