Closed mdeprezzo closed 10 years ago
Could you provide the code you are trying to run.
Sure,
// Load HTML from string $loaded = $dom->loadHTML(mb_convert_encoding($pFilename, 'HTML-ENTITIES', 'UTF-8'));
This is the function inside the Readers class,
In a controller i've this call:
Excel::loadView('admin.clients.folder.format', array('data' => $clients))
->setTitle('Clienti')
->sheet('Lista Clienti')
->export('xls');
i cant post the html code, but i notice that when i've some htmlentities like '& agrave ;' or similar i got this error. And if i try to sopprime with '@' before loadHTML call, in that cell with htmlentities data i see FALSE
Are you sure you are using the last version of the package? (https://github.com/Maatwebsite/laravel4-PHPExcel/blob/master/src/Maatwebsite/Excel/Readers/HTML_reader.php#L193) The dom loadHTML is already silenced.
A while back we got an issue with the '&'-sign. Silencing the loadHTML which kind of solved the issue. But it will not fix the problem, it will only hide the warnings.
A better fix is to use the html equivalent of '&', which is &
Best is to escape the echo in which these characters appear. You can use the blade syntax with the tripple braces( {{{ }}}
)
Ok, i've update with the last version of this package. But like u said the problem still remains. I'll try to use the equivalent of & in html entities, but i need to convert all the entities à, because if i just convert o replace & with & the html conversion of à character doesn't works
Why i've problem with accents ? What's wrong with that ?
Silencing the loadHTML for me doesn't works, so i'm crazy for that solution.
I've an update. I'm trying to load on my webserver the new package, and works perfect. On localhost i've that error. So excuse me guys. Maybe some settings about php ?
Try throwing away the vendor folder and the composer.lock file on your localhost. Then do composer install
. The latest version of the package should be installed.
I'm with the same error and here is my code:
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>
@felipesmendes Please open a new issue for it and use the issue template.
When i try to export some data like xls file i've got this error
DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity
why ? Can u help me ?