<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Test_excel extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->library('phpexcel');
    }

    public function index()
    {
        echo "<h1>Testing PHPExcel Library</h1>";

        // Test 1: Create Excel
        $this->phpexcel->create();
        $this->phpexcel->setCellValue('A1', 'Hello World');
        $this->phpexcel->save(FCPATH . 'test.xlsx');
        echo "<p>1. File created: test.xlsx</p>";

        // Test 2: Validate file
        $is_valid = $this->phpexcel->validateFile(FCPATH . 'test.xlsx');
        echo "<p>2. File validation: " . ($is_valid ? 'Valid' : 'Invalid') . "</p>";

        // Test 3: Read file
        $data = $this->phpexcel->readToArray(FCPATH . 'test.xlsx');
        echo "<p>3. Data read: " . print_r($data, true) . "</p>";

        // Clean up
        if (file_exists(FCPATH . 'test.xlsx')) {
            unlink(FCPATH . 'test.xlsx');
        }
    }
}
