@@ -443,11 +443,14 @@ def _convert_to_protection(cls, protection_dict):
443
443
def _write_cells (
444
444
self ,
445
445
cells ,
446
+ notes ,
446
447
sheet_name : str | None = None ,
447
448
startrow : int = 0 ,
448
449
startcol : int = 0 ,
449
450
freeze_panes : tuple [int , int ] | None = None ,
450
451
) -> None :
452
+ from openpyxl .comments import Comment
453
+
451
454
# Write the frame cells using openpyxl.
452
455
sheet_name = self ._get_sheet_name (sheet_name )
453
456
@@ -484,7 +487,11 @@ def _write_cells(
484
487
row = freeze_panes [0 ] + 1 , column = freeze_panes [1 ] + 1
485
488
)
486
489
490
+ notes_col = None
491
+
487
492
for cell in cells :
493
+ if notes_col is None :
494
+ notes_col = startcol + cell .col + 1
488
495
xcell = wks .cell (
489
496
row = startrow + cell .row + 1 , column = startcol + cell .col + 1
490
497
)
@@ -530,6 +537,19 @@ def _write_cells(
530
537
for k , v in style_kwargs .items ():
531
538
setattr (xcell , k , v )
532
539
540
+ if notes is None :
541
+ return
542
+
543
+ for row_idx , (_ , row ) in enumerate (notes .iterrows ()):
544
+ for col_idx , note in enumerate (row ):
545
+ xcell = wks .cell (
546
+ row = row_idx + 2 , # openpyxl starts counting at 1, not 0
547
+ column = col_idx + notes_col ,
548
+ )
549
+ if note :
550
+ comment = Comment (note , "" )
551
+ xcell .comment = comment
552
+
533
553
534
554
class OpenpyxlReader (BaseExcelReader ["Workbook" ]):
535
555
@doc (storage_options = _shared_docs ["storage_options" ])
0 commit comments