Search code examples
phpexcellaravellaravel-5.3

Laravel excel read xls like html


I'm using in my program Maatwebsite/Laravel-Excel package to import xls/xlsx files. In most of the case the import go good, and the program read perfectly the rows so how they are in the file. But sometimes it reads rows just like if they are including in html tag. This depending by package or by xls file creation?

This is how should return: Photo1

This is instead how it returns: Photo2

UPDATE: MY CODE

public function preparaCampiMappaturaXLS($riga_inizio_importazione, $intestazione, $file) {
    $res = null;
    Excel::load($file, function($reader) use($riga_inizio_importazione, $intestazione, &$res) {
        $sheet = $reader->first()->toArray();

        // Calcolo l'indice da cui estrapolare i campi da far visualizzare per la mappatura
        if ($intestazione) {
            $index = $riga_inizio_importazione - 2;
        } else {
            $index = $riga_inizio_importazione - 1;
        }

        if (!array_key_exists($index, $sheet)) {
            throw new \App\Exceptions\InvalidIndexException("La riga selezionata non è presente all'interno del file");
        }

        $res = $sheet[$index];
    });

    return $res;
}

Solution

  • Laravel package is working fine for you, You can replace from

     $res = $sheet[$index];
    

    To

     $res = trim(strip_tags($sheet[$index]));