我在我的程序Maatwebsite / Laravel-Excel包中导入xls / xlsx文件。在大多数情况下,导入变得很好,并且程序完全读取行以及它们在文件中的位置。但有时它会读取行,就像它们包含在html标记中一样。这取决于包还是xls文件创建?
更新:我的代码
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;
}
答案 0 :(得分:2)
Laravel包适合您,您可以从
替换 $res = $sheet[$index];
要
$res = trim(strip_tags($sheet[$index]));