HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/dvpis2026/dvpis.kaunokolegija.lt/src/Controller/ExcelController.php
<?php

namespace App\Controller;

use PhpOffice\PhpSpreadsheet\IOFactory;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;

/**
 * Excel controller.
 */
#[Route(path: 'excel')]
class ExcelController extends AbstractController
{
    public function __construct(
        private readonly KernelInterface $kernel,
    ) {
    }
    /**
     * Lists all academicUnit entities.
     *
     * @Method("GET")
     */
    #[Route(path: '/', name: 'excel_index')]
    public function indexAction()
    {
        $rootDir = $this->kernel->getProjectDir();
        $objExcel = IOFactory::load($rootDir . '/web/uploads/excel/2LENTELE.xlsx');
        define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

        $worksheet = $objExcel->setActiveSheetIndex(0);

        foreach ($worksheet->getRowIterator() as $row) {
            echo '    Row number - ', $row->getRowIndex(), EOL;

            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
            foreach ($cellIterator as $cell) {
                if (!is_null($cell)) {
                    echo '        Cell - ', $cell->getCoordinate(), ' - ', $cell->getCalculatedValue(), EOL;
                }
            }
        }

        exit;
    }
}