有什么方法可以加快我的功能以处理更大的 excel 文件?有我的代码:
$excelService = $this->get('xls.service_xls5');
$excelObj = $this->get('xls.load_xls5')->setReadDataOnly(true)->load('../web/bundles/static/pliki/'.$name);
$sheet = $excelObj->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 1; $row <= $highestRow; $row++){
$nazwaKlienta = $sheet->getCellByColumnAndRow(0,$row)->getValue();
$ulica = $sheet->getCellByColumnAndRow(1,$row)->getValue();
$miasto = $sheet->getCellByColumnAndRow(2,$row)->getValue();
$kod = $sheet->getCellByColumnAndRow(3,$row)->getValue();
$notatka = $sheet->getCellByColumnAndRow(4,$row)->getValue();
$kolor = $sheet->getCellByColumnAndRow(5,$row)->getValue();
if ($row == $highestRow) {
$excelObj->disconnectWorksheets();
unset($excelObj);
}
$em = $this->getDoctrine()->getManager();
$klient = new Klient();
$klient->setNazwa($nazwaKlienta);
(...)
$em->persist($klient);
$em->flush();
$klientId = $klient->getId();
$punkt = new Punkty();
$punkt->setIdKlienta($klient);
$em->persist($punkt);
$em->flush();
}
此代码打开一个现有的 excel 文件并读取所有数据并将其写入数据库。它适用于大约 150-200 的数据量,但我需要处理大约 2000 行的数据。我如何使用 phpexcelBundle 缓存它,或者还有其他方法?