<?php
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\IOFactory;

$inputFileName = 'khachhang.xlsx';

try {
    $spreadsheet = IOFactory::load($inputFileName);
    $worksheet = $spreadsheet->getActiveSheet();
    $rows = $worksheet->toArray();

    echo "--- HEADER COLUMNS ---\n";
    if (isset($rows[0])) {
        foreach ($rows[0] as $index => $header) {
            echo "Col " . $index . ": " . ($header ?? "NULL") . "\n";
        }
    }

    echo "\n--- SAMPLE DATA (Rows 2-5) ---\n";
    for ($i = 1; $i <= 4; $i++) {
        if (isset($rows[$i])) {
            echo "Row " . ($i + 1) . ": " . implode(" | ", array_map(fn($v) => $v ?? "NULL", $rows[$i])) . "\n";
        }
    }
} catch (Exception $e) {
    echo 'Error loading file: ' . $e->getMessage();
}
