<?php
spl_autoload_register(function ($class) {
    // Only handle PhpOffice classes
    $prefix = 'PhpOffice\\PhpSpreadsheet\\';
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }
    
    // Your folder structure: /phpspreadsheet/PhpSpreadsheet/
    $base_dir = __DIR__ . '/phpspreadsheet/PhpSpreadsheet/';
    
    $relative_class = substr($class, $len);
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
    
    if (file_exists($file)) {
        require $file;
    }
});