import openpyxl
import json
import os

file_path = r'c:\laragon\www\sgmi\docs\estudiantes activos 2023-2026.xlsx'

if not os.path.exists(file_path):
    print(json.dumps({"error": f"File not found: {file_path}"}))
    exit(1)

try:
    workbook = openpyxl.load_workbook(file_path, read_only=True)
    sheet = workbook.active
    
    # Read first 30 rows to find headers
    rows = []
    for row in sheet.iter_rows(max_row=30):
        rows.append([cell.value for cell in row])
        
    print(json.dumps({
        "rows": rows
    }, indent=2, default=str))

except Exception as e:
    print(json.dumps({"error": str(e)}))
