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

Update updated_word.py

Browse files
Files changed (1) hide show
  1. updated_word.py +46 -48
updated_word.py CHANGED
@@ -727,10 +727,9 @@ def handle_attendance_list_table_enhanced(table, flat_json):
727
  print(f" ❌ No attendance data found in JSON")
728
  return 0
729
 
730
- # Format the attendance data
731
  # Format the attendance data
732
  if isinstance(attendance_value, list):
733
- # Each item in the list should be on a separate line
734
  formatted_attendance = '\n'.join(str(item).strip() for item in attendance_value if str(item).strip())
735
  else:
736
  formatted_attendance = str(attendance_value)
@@ -777,47 +776,12 @@ def handle_attendance_list_table_enhanced(table, flat_json):
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 = ''
@@ -834,15 +798,49 @@ else:
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
 
847
  return replacements_made
848
 
 
727
  print(f" ❌ No attendance data found in JSON")
728
  return 0
729
 
 
730
  # Format the attendance data
731
  if isinstance(attendance_value, list):
732
+ # Each item in the list should be on a separate line
733
  formatted_attendance = '\n'.join(str(item).strip() for item in attendance_value if str(item).strip())
734
  else:
735
  formatted_attendance = str(attendance_value)
 
776
  target_cell = target_row.cells[found_attendance_cell]
777
 
778
  # Replace the content
779
+ if has_red_text(target_cell):
780
+ print(f" πŸ”§ Replacing red text in target cell...")
 
 
 
 
 
 
 
 
 
 
 
 
781
 
782
+ # πŸ”§ SPECIAL FIX: Handle line breaks properly in Word
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783
  if isinstance(attendance_value, list) and len(attendance_value) > 1:
784
+ # Clear existing content first
785
  for paragraph in target_cell.paragraphs:
786
  for run in paragraph.runs:
787
  run.text = ''
 
798
  new_paragraph.text = item_text
799
 
800
  replacements_made += 1
801
+ print(f" βœ… Added {len(attendance_value)} separate lines to attendance cell")
802
  else:
803
+ # Single item - use normal replacement
804
+ cell_replacements = replace_red_text_in_cell(target_cell, formatted_attendance)
805
+ replacements_made += cell_replacements
806
+
807
+ print(f" πŸ“Š Replacements made: {replacements_made}")
808
+ else:
809
+ # If no red text, try to replace content anyway
810
+ current_text = get_clean_text(target_cell).strip()
811
+ print(f" πŸ“‹ No red text found, current cell text: '{current_text[:50]}...'")
812
+
813
+ if len(current_text) > 50: # If it contains what looks like attendance data
814
+ print(f" πŸ”§ Replacing entire cell content...")
815
+
816
+ # πŸ”§ SPECIAL FIX: Handle line breaks properly for non-red text too
817
+ if isinstance(attendance_value, list) and len(attendance_value) > 1:
818
+ # Clear existing content
819
+ for paragraph in target_cell.paragraphs:
820
+ for run in paragraph.runs:
821
+ run.text = ''
822
+
823
+ # Add first item to first paragraph
824
+ if target_cell.paragraphs:
825
+ target_cell.paragraphs[0].text = str(attendance_value[0]).strip()
826
+
827
+ # Add remaining items as new paragraphs
828
+ for item in attendance_value[1:]:
829
+ item_text = str(item).strip()
830
+ if item_text:
831
+ new_paragraph = target_cell.add_paragraph()
832
+ new_paragraph.text = item_text
833
+
834
+ replacements_made += 1
835
+ print(f" βœ… Added {len(attendance_value)} separate lines to cell")
836
  else:
837
+ # Single item
838
+ if target_cell.paragraphs:
839
+ target_cell.paragraphs[0].text = formatted_attendance
840
+ else:
841
+ target_cell.text = formatted_attendance
842
+ replacements_made += 1
843
+ print(f" βœ… Replaced entire cell content")
844
 
845
  return replacements_made
846