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
    
    # Get headers (first row)
    headers = [cell.value for cell in next(sheet.iter_rows(max_row=1))]
    
    # Get first 3 rows of data
    sample_data = []
    for row in sheet.iter_rows(min_row=2, max_row=4):
        sample_data.append([cell.value for cell in row])
        
    print(json.dumps({
        "headers": headers,
        "sample_data": sample_data
    }, indent=2, default=str))

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