Laravel excel读取像HTML一样的xls

时间:2017-09-02 08:53:44

标签: php excel laravel laravel-5.3

我在我的程序Maatwebsite / Laravel-Excel包中导入xls / xlsx文件。在大多数情况下,导入变得很好,并且程序完全读取行以及它们在文件中的位置。但有时它会读取行,就像它们包含在html标记中一样。这取决于包还是xls文件创建?

这是应该如何返回: Photo1

这是它返回的方式: Photo2

更新:我的代码

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;
}

1 个答案:

答案 0 :(得分:2)

Laravel包适合您,您可以从

替换
 $res = $sheet[$index];

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