Spaces:
Sleeping
Sleeping
File size: 729 Bytes
bd161ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from docx import Document
import os
from typing import Optional
def extract_output_template_from_docx(docx_path: str) -> str:
"""Extracts the output template text from a .docx file (all paragraphs concatenated)."""
doc = Document(docx_path)
output = []
for para in doc.paragraphs:
text = para.text.strip()
if text:
output.append(text)
return '\n'.join(output)
def find_output_docx_file_in_folder(folder_path: str) -> Optional[str]:
"""Finds the first .docx file in a folder and returns its path, or None if not found."""
for fname in os.listdir(folder_path):
if fname.lower().endswith('.docx'):
return os.path.join(folder_path, fname)
return None |