Shami96 commited on
Commit
a5282db
Β·
verified Β·
1 Parent(s): c695f61

Update updated_word.py

Browse files
Files changed (1) hide show
  1. updated_word.py +53 -12
updated_word.py CHANGED
@@ -777,29 +777,70 @@ def handle_attendance_list_table_enhanced(table, flat_json):
777
  target_cell = target_row.cells[found_attendance_cell]
778
 
779
  # Replace the content
780
- if has_red_text(target_cell):
781
- print(f" πŸ”§ Replacing red text in target cell...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782
  cell_replacements = replace_red_text_in_cell(target_cell, formatted_attendance)
783
  replacements_made += cell_replacements
784
- print(f" βœ… Replaced red text in attendance list")
785
- print(f" πŸ“Š Replacements made: {cell_replacements}")
786
- else:
787
- # If no red text, try to replace content anyway
788
- current_text = get_clean_text(target_cell).strip()
789
- print(f" πŸ“‹ No red text found, current cell text: '{current_text[:50]}...'")
 
 
 
790
 
791
- if len(current_text) > 50: # If it contains what looks like attendance data
792
- print(f" πŸ”§ Replacing entire cell content...")
793
- # Clear and replace
794
  for paragraph in target_cell.paragraphs:
795
  for run in paragraph.runs:
796
  run.text = ''
797
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
  if target_cell.paragraphs:
799
  target_cell.paragraphs[0].text = formatted_attendance
800
  else:
801
  target_cell.text = formatted_attendance
802
-
803
  replacements_made += 1
804
  print(f" βœ… Replaced entire cell content")
805
 
 
777
  target_cell = target_row.cells[found_attendance_cell]
778
 
779
  # Replace the content
780
+ # Replace the content
781
+ if has_red_text(target_cell):
782
+ print(f" πŸ”§ Replacing red text in target cell...")
783
+
784
+ # πŸ”§ SPECIAL FIX: Handle line breaks properly in Word
785
+ if isinstance(attendance_value, list) and len(attendance_value) > 1:
786
+ # Clear existing content first
787
+ for paragraph in target_cell.paragraphs:
788
+ for run in paragraph.runs:
789
+ run.text = ''
790
+
791
+ # Add first item to first paragraph
792
+ if target_cell.paragraphs:
793
+ target_cell.paragraphs[0].text = str(attendance_value[0]).strip()
794
+
795
+ # Add remaining items as new paragraphs
796
+ for item in attendance_value[1:]:
797
+ item_text = str(item).strip()
798
+ if item_text:
799
+ new_paragraph = target_cell.add_paragraph()
800
+ new_paragraph.text = item_text
801
+
802
+ replacements_made += 1
803
+ print(f" βœ… Added {len(attendance_value)} separate lines to attendance cell")
804
+ else:
805
+ # Single item - use normal replacement
806
  cell_replacements = replace_red_text_in_cell(target_cell, formatted_attendance)
807
  replacements_made += cell_replacements
808
+
809
+ print(f" πŸ“Š Replacements made: {replacements_made}")
810
+ else:
811
+ # If no red text, try to replace content anyway
812
+ current_text = get_clean_text(target_cell).strip()
813
+ print(f" πŸ“‹ No red text found, current cell text: '{current_text[:50]}...'")
814
+
815
+ if len(current_text) > 50: # If it contains what looks like attendance data
816
+ print(f" πŸ”§ Replacing entire cell content...")
817
 
818
+ # πŸ”§ SPECIAL FIX: Handle line breaks properly for non-red text too
819
+ if isinstance(attendance_value, list) and len(attendance_value) > 1:
820
+ # Clear existing content
821
  for paragraph in target_cell.paragraphs:
822
  for run in paragraph.runs:
823
  run.text = ''
824
 
825
+ # Add first item to first paragraph
826
+ if target_cell.paragraphs:
827
+ target_cell.paragraphs[0].text = str(attendance_value[0]).strip()
828
+
829
+ # Add remaining items as new paragraphs
830
+ for item in attendance_value[1:]:
831
+ item_text = str(item).strip()
832
+ if item_text:
833
+ new_paragraph = target_cell.add_paragraph()
834
+ new_paragraph.text = item_text
835
+
836
+ replacements_made += 1
837
+ print(f" βœ… Added {len(attendance_value)} separate lines to cell")
838
+ else:
839
+ # Single item
840
  if target_cell.paragraphs:
841
  target_cell.paragraphs[0].text = formatted_attendance
842
  else:
843
  target_cell.text = formatted_attendance
 
844
  replacements_made += 1
845
  print(f" βœ… Replaced entire cell content")
846