"""XLSX text extraction using openpyxl."""

from openpyxl import load_workbook


def extract_xlsx(file_path: str) -> str:
    """Extract text from an XLSX file."""
    wb = load_workbook(file_path, read_only=True, data_only=True)
    sheets = []

    for sheet_name in wb.sheetnames:
        ws = wb[sheet_name]
        rows = []
        for row in ws.iter_rows(values_only=True):
            cells = [str(c) for c in row if c is not None]
            if cells:
                rows.append(" | ".join(cells))
        if rows:
            sheets.append(f"[{sheet_name}]\n" + "\n".join(rows))

    wb.close()
    return "\n\n".join(sheets)
