File tree 3 files changed +26
-0
lines changed
3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1209,6 +1209,7 @@ def book(self) -> _WorkbookT:
1209
1209
def _write_cells (
1210
1210
self ,
1211
1211
cells ,
1212
+ notes ,
1212
1213
sheet_name : str | None = None ,
1213
1214
startrow : int = 0 ,
1214
1215
startcol : int = 0 ,
@@ -1221,6 +1222,8 @@ def _write_cells(
1221
1222
----------
1222
1223
cells : generator
1223
1224
cell of formatted data to save to Excel sheet
1225
+ notes : dataframe
1226
+ dataframe that holds notes to write
1224
1227
sheet_name : str, default None
1225
1228
Name of Excel sheet, if None, then use self.cur_sheet
1226
1229
startrow : upper left cell row to dump data frame
Original file line number Diff line number Diff line change @@ -241,6 +241,7 @@ def _save(self) -> None:
241
241
def _write_cells (
242
242
self ,
243
243
cells ,
244
+ notes ,
244
245
sheet_name : str | None = None ,
245
246
startrow : int = 0 ,
246
247
startcol : int = 0 ,
@@ -258,6 +259,8 @@ def _write_cells(
258
259
if validate_freeze_panes (freeze_panes ):
259
260
wks .freeze_panes (* (freeze_panes ))
260
261
262
+ notes_col = None
263
+
261
264
for cell in cells :
262
265
val , fmt = self ._value_with_fmt (cell .val )
263
266
@@ -281,4 +284,17 @@ def _write_cells(
281
284
style ,
282
285
)
283
286
else :
287
+ if notes_col is None :
288
+ notes_col = startcol + cell .col
284
289
wks .write (startrow + cell .row , startcol + cell .col , val , style )
290
+
291
+ if notes is None :
292
+ return
293
+
294
+ for row_idx , (_ , row ) in enumerate (notes .iterrows ()):
295
+ for col_idx , note in enumerate (row ):
296
+ wks .write_comment (
297
+ row_idx + 1 , # first row has columns
298
+ col_idx + notes_col , # n columns with indexes
299
+ str (note ),
300
+ )
Original file line number Diff line number Diff line change @@ -554,6 +554,9 @@ def __init__(
554
554
self .rowcounter = 0
555
555
self .na_rep = na_rep
556
556
if not isinstance (df , DataFrame ):
557
+ self .notes = None
558
+ if df .tooltips is not None :
559
+ self .notes = df .tooltips .tt_data
557
560
self .styler = df
558
561
self .styler ._compute () # calculate applied styles
559
562
df = df .data
@@ -880,6 +883,9 @@ def get_formatted_cells(self) -> Iterable[ExcelCell]:
880
883
cell .val = self ._format_value (cell .val )
881
884
yield cell
882
885
886
+ def get_notes (self ) -> Iterable [str ]:
887
+ yield from self .notes .iterrows ()
888
+
883
889
@doc (storage_options = _shared_docs ["storage_options" ])
884
890
def write (
885
891
self ,
@@ -941,6 +947,7 @@ def write(
941
947
try :
942
948
writer ._write_cells (
943
949
formatted_cells ,
950
+ self .notes ,
944
951
sheet_name ,
945
952
startrow = startrow ,
946
953
startcol = startcol ,
You can’t perform that action at this time.
0 commit comments