SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.3k stars 1.93k forks source link

[BUG] DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity #2514

Closed felipesmendes closed 4 years ago

felipesmendes commented 4 years ago

Prerequisites

Versions

Description

I'm trying to export a CSV file

Steps to Reproduce

Call the controller method and wait.

Expected behavior: The CSV file complete

Actual behavior: The script stops and give this Exception: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity

Additional Information

Here ir my codes: Controller Call:

       return Excel::download(new PosicoesExport($posicoes, $logo, $vet_campos, $clientes, $veiculos, $rastreadores, $motivos_transmissao),$posicoes[0]->veiculo->placa." - ".$posicoes[0]->veiculo->cliente->nome.".csv", \Maatwebsite\Excel\Excel::CSV);

Export:

<?php
namespace App\Exports;

use App\Posicao;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;

class PosicoesExport implements FromView,WithCustomCsvSettings
{
    public function __construct($posicoes, $logo, $campos, $clientes, $veiculos, $rastreadores, $motivos_transmissao){
        $this->dados = compact('posicoes','logo','campos','clientes','veiculos','rastreadores','motivos_transmissao');
    }
    public function view(): View
    {
        return view('posicao.posicaoexcel', $this->dados);
    }

    public function getCsvSettings(): array
    {
        return [
            'use_bom' => true
        ];
    }

}
?>

View:

<html>
    <tr align="center">
        <th>Veículo</th>
        <th>Data</th>
        @if(!empty($campos))
        @foreach ($campos as $campo)
        @if($campo['listar'])
        <th>{{{$campo['label']}}}</th>
        @endif
        @endforeach
        @endif
    </tr>
    @foreach ($posicoes as $posicao)
    <tr align="center">
        <td>{{{$posicao->veiculo->placa}}}</td>
        <td>@datetime($posicao->data_recebimento)</td>
        @foreach ($campos as $campo)
        @if($campo['listar'])
        @if($campo['valor'] == 'cliente')
        <td>{{{$posicao->cliente->nome}}}</td>
        @elseif($campo['valor'] == 'veiculo')
        <td>{{{$posicao->veiculo->placa}}}</td>
        @elseif($campo['valor'] == 'velocidade')
            <?php 
            $flag = "";
            $vel = 0;
            if (isset($posicao->velocidade)) {
                $vel = $posicao->velocidade;
            } else {
                $vel = 0;
            }

            if (is_null($posicao->ignicao) || $posicao->ignicao != 1) {
                $vel = 0;
                $flag = "background-color:#000000;color:#FFFFFF;";
            } else {
                if ($vel == 0)
                    $flag = "background-color:#CCCCCC;color:#000000;";
                else if ($vel <= 20)
                    $flag = "background-color:##45a7e8;color:#000000;";
                else if ($vel <= 40)
                    $flag = "background-color:#0000FF;color:#FFFFFF;";
                else if ($vel <= 60)
                    $flag = "background-color:#00FF00;color:#000000;";
                else if ($vel <= 80)
                    $flag = "background-color:#FFFF00;color:#000000;";
                else if ($vel <= 100)
                    $flag = "background-color:#FFA500;color:#000000;";
                else
                    $flag = "background-color:#a333c8;color:#FFFFFF;";
                    // $flag = "background-color:#FF0000;color:#FFFFFF;";

            }
            echo "<td style=\"$flag\" >$vel</td>";
            ?>
        @elseif($campo['valor'] == 'rastreador')
        <td>{{{$posicao->rastreador->identificador}}}</td>
        @elseif($campo['valor'] == 'data_recebimento')
        <td>@datetime($posicao->data_recebimento)</td>
        @elseif($campo['valor'] == 'created_at')
        <td>@datetime($posicao->created_at)</td>
        @elseif($campo['valor'] == 'motivo_transmissao')
        <td>@if(is_object($posicao->motivo)){{{$posicao->motivo->nome}}}@endif</td>
        @elseif($campo['valor'] == 'latitude')
        <td>{{{str_replace(',','.',$posicao->latitude)}}}</td>
        @elseif($campo['valor'] == 'longitude')
        <td>{{{str_replace(',','.',$posicao->longitude)}}}</td>
        @elseif($campo['valor'] == 'descricao')
            <td>
                {{{$posicao->veiculo->descricao}}}
            </td>
        @elseif($campo['valor'] == 'local_cerca_id')
            @if($posicao->posicao_id)
            <td>
                @foreach($posicao->local($posicao->posicao_id) as $cerca_loi)
                    <span class="item">{{{$cerca_loi["local_cerca"]}}}</span> - 
                @endforeach
            </td>
            @else
            <td> -- </td>
            @endif
        @elseif($campo['valor'] == 'velocidade_maxima_seco')
            @if($posicao->posicao_id)
                <td>
                    @foreach($posicao->local($posicao->posicao_id) as $cerca_loi)
                        @if($cerca_loi["flg_tipo"] == 1)
                        <span class="item">{{{$cerca_loi["velocidade_maxima_seco"]}}}</span> - 
                        @endif
                    @endforeach
                </td>
            @else
                <td></td>
            @endif
        @elseif($campo['valor'] == 'velocidade_maxima_chuva')
            @if($posicao->posicao_id)
                <td>
                    @foreach($posicao->local($posicao->posicao_id) as $cerca_loi)
                        @if($cerca_loi["flg_tipo"] == 1)
                        <span class="item">{{{$cerca_loi["velocidade_maxima_chuva"]}}}</span> - 
                        @endif 
                    @endforeach
                </td>
            @else
                <td></td>
            @endif
        @else
        <td><?php echo $posicao->{$campo['valor']} ?></td>
        @endif
        @endif
        @endforeach
    </tr>
    @endforeach

</html>
patrickbrouwers commented 4 years ago

Your html looks invalid: no table tags, no tbody tag.