如果行数太多,PHPExcel会使文件无法读取
您好,我使用PHPExcel生成xls文件,它运行良好(即使使用6000行文件),但当我尝试使用9000行(我没有尝试使用8000行)时,它会使文件无法用Excel读取 这是我的密码:如果行数太多,PHPExcel会使文件无法读取,php,symfony,Php,Symfony,您好,我使用PHPExcel生成xls文件,它运行良好(即使使用6000行文件),但当我尝试使用9000行(我没有尝试使用8000行)时,它会使文件无法用Excel读取 这是我的密码: public function generationExcelAction(Request $request) { /* * set_time_limit & ini_set on été ajouté afin d'éviter le timeout lors d'un export
public function generationExcelAction(Request $request)
{
/*
* set_time_limit & ini_set on été ajouté afin d'éviter le timeout lors d'un export excel trop volumineux.
*/
set_time_limit (0);
ini_set('memory_limit', '-1');
$this->getDoctrine()->getConnection()->getConfiguration()->setSQLLogger(null);
/** @var \Nalods\Entity\ArticleRepository $repoArticles */
$repoArticles = $this->getDoctrine()->getRepository('Nalods\Entity\Article');
$requeteArticle = $repoArticles->findByPlateforme($this->getUser()->getPlateforme()->getId());
$filter = new ReassortFilter();
$filterForm = $this->createForm(
ReassortFilterType::class,
$filter,
[
'arbo' => $this->getArborescenceManager()->getArborescenceForReassort(),
'fournisseurs' => $this->getDoctrine()->getRepository('Nalods\Entity\FournisseurCommun')->getFournisseursForReassort($this->getUser()->getPlateforme()->getId()),
]
);
$filterForm->handleRequest($request);
$requeteArticle = $repoArticles->applyFilters($requeteArticle, $filter, $request->getSession()->get(Commande::ID_SESSION));
$requeteArticle->select('DISTINCT a.id');
$listeIdArticles = $requeteArticle->getQuery()->getScalarResult();
$response = new StreamedResponse();
$response->setCallback(function () use ($listeIdArticles) {
// Crée un nouveau objet PHPExcel
$objPHPExcel = new PHPExcel();
// Initialise les propriété du classeur Excel
$objPHPExcel->getProperties()->setCreator("Nalod's")
->setLastModifiedBy("Nalod's")
->setTitle("Export XLS");
// Ajout de la ligne d'entête de colonne
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Code Centrale')
->setCellValue('B1', 'Désignation')
->setCellValue('C1', 'Gencod')
->setCellValue('D1', 'Réf Produit')
->setCellValue('E1', 'N°Rayon')
->setCellValue('F1', 'Rayon')
->setCellValue('G1', 'N°Famille')
->setCellValue('H1', 'Famille')
->setCellValue('I1', 'N°Sous famille')
->setCellValue('J1', 'Sous famille')
->setCellValue('K1', 'N° Gamme')
->setCellValue('L1', 'Unité d\'achat')
->setCellValue('M1', 'Unité de vente')
->setCellValue('N1', 'Nombre UV / UA')
->setCellValue('O1', 'Colisage')
->setCellValue('P1', 'Appro Mini')
->setCellValue('Q1', 'Prix achat brut')
->setCellValue('R1', 'Remise magasin 1')
->setCellValue('S1', 'Remise magasin 2')
->setCellValue('T1', 'Remise magasin 3')
->setCellValue('U1', 'Remise magasin 4')
->setCellValue('V1', 'Remise magasin 5')
->setCellValue('W1', 'Pa net sans remise de base')
->setCellValue('X1', 'Prix achat Net')
->setCellValue('Y1', 'Coefficient')
->setCellValue('Z1', 'Taux marge')
->setCellValue('AA1', 'Prix vente conseillé')
->setCellValue('AB1', 'Taux de TVA')
->setCellValue('AC1', 'Date Début Validité')
->setCellValue('AD1', 'Date Fin Validité')
->setCellValue('AE1', 'Date MAJ')
->setCellValue('AF1', 'N°Fournisseur')
->setCellValue('AG1', 'Caractéristiques')
->setCellValue('AH1', 'Marque')
->setCellValue('AI1', 'Montant_ttc_ecotaxe')
->setCellValue('AJ1', 'Montant écomobilier')
->setCellValue('AK1', 'Stock disponible');
$i = 0;
$j = 0;
$listeBatch = array();
$total = count($listeIdArticles);
while ($i < $total) {
$listeBatch[] = $listeIdArticles[$i]['id'];
if ($j < 50 && $i != $total - 1) {
$j++;
} else {
$repoArticles = $this->getDoctrine()->getRepository('Nalods\Entity\Article');
$requeteArticle = $repoArticles->findByPlateforme($this->getUser()->getPlateforme()->getId());
$requeteArticle->andWhere($requeteArticle->expr()->in('a.id', $listeBatch));
$listeArticles = $requeteArticle->getQuery()->getResult();
/** @var \Nalods\Entity\Article $article */
foreach ($listeArticles as $k => $article) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.($i-$j+$k+2), $article->getId())
->setCellValue('B'.($i-$j+$k+2), $article->getNom())
->setCellValue('C'.($i-$j+$k+2), $article->getArticleGencod()->first()->getGencod()->getCodeBarreComplet())
->setCellValue('D'.($i-$j+$k+2), $article->getArticlePlateforme()->first()->getReferenceFournisseur())
->setCellValue('E'.($i-$j+$k+2), $article->getSousFamille()->getFamille()->getRayon()->getId())
->setCellValue('F'.($i-$j+$k+2), $article->getSousFamille()->getFamille()->getRayon()->getLibelleComplet())
->setCellValue('G'.($i-$j+$k+2), $article->getSousFamille()->getFamille()->getId())
->setCellValue('H'.($i-$j+$k+2), $article->getSousFamille()->getFamille()->getLibelleComplet())
->setCellValue('I'.($i-$j+$k+2), $article->getSousFamille()->getId())
->setCellValue('J'.($i-$j+$k+2), $article->getSousFamille()->getLibelleComplet())
->setCellValue('K'.($i-$j+$k+2), $article->getGamme())
->setCellValue('L'.($i-$j+$k+2), $article->getUniteAchatComplete())
->setCellValue('M'.($i-$j+$k+2), $article->getUniteVenteComplete())
->setCellValue('N'.($i-$j+$k+2), $article->getNombreUvParUa())
->setCellValue('O'.($i-$j+$k+2), $article->getArticlePlateforme()->first()->getColisage())
->setCellValue('P'.($i-$j+$k+2), ($article->getArticlePlateforme()->first()->getPrixActuels()->first()->getQuantiteMinimum()) ? $article->getArticlePlateforme()->first()->getPrixActuels()->first()->getQuantiteMinimum() : $article->getArticlePlateforme()->first()->getMinimumCommande())
->setCellValue('Q'.($i-$j+$k+2), 0)
->setCellValue('R'.($i-$j+$k+2), 0)
->setCellValue('S'.($i-$j+$k+2), 0)
->setCellValue('T'.($i-$j+$k+2), 0)
->setCellValue('U'.($i-$j+$k+2), 0)
->setCellValue('V'.($i-$j+$k+2), 0)
->setCellValue('W'.($i-$j+$k+2), 'VRAI')
->setCellValue('X'.($i-$j+$k+2), $article->getArticlePlateforme()->first()->getPrixActuels()->first()->getPrixNet())
->setCellValue('Y'.($i-$j+$k+2), round(($article->getPrixVenteConseille()/$article->getArticlePlateforme()->first()->getPrixActuels()->first()->getPrixNet()),2)) //Coefficient : PVTTC/PAHT
->setCellValue('Z'.($i-$j+$k+2), round(((($article->getPrixVenteConseille()/(1+($article->getTauxTva()->getTaux()/100)))-$article->getArticlePlateforme()->first()->getPrixActuels()->first()->getPrixNet())/($article->getPrixVenteConseille()/(1+($article->getTauxTva()->getTaux()/100))))*100,2)) //Taux de marge : (PVHT-PAHT)/PVHT
->setCellValue('AA'.($i-$j+$k+2), $article->getPrixVenteConseille())
->setCellValue('AB'.($i-$j+$k+2), $article->getTauxTva()->getTaux())
->setCellValue('AC'.($i-$j+$k+2), $article->getArticlePlateforme()->first()->getPrixActuels()->first()->getDateDebut()->format('d/m/Y'))
->setCellValue('AD'.($i-$j+$k+2), $article->getArticlePlateforme()->first()->getPrixActuels()->first()->getDateFin()->format('d/m/Y'))
->setCellValue('AE'.($i-$j+$k+2), date_format(new \DateTime(), 'd/m/Y'))
->setCellValue('AF'.($i-$j+$k+2), $this->getUser()->getPlateforme()->getId())//N°Plateforme=N°Fournisseur
->setCellValue('AG'.($i-$j+$k+2), '')
->setCellValue('AH'.($i-$j+$k+2), $article->getMarqueLibelle())
->setCellValue('AI'.($i-$j+$k+2), $article->getEcoContribution())
->setCellValue('AJ'.($i-$j+$k+2), $article->getEcoMobilier())
->setCellValue('AK'.($i-$j+$k+2), $article->getArticlePlateforme()->first()->getStock());
}
$j = 0;
$listeBatch = array();
$this->getDoctrine()->getManager()->clear();
}
$i++;
}
// Enregistre le fichier Excel
$writer = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$writer->save('php://output');
});
$response->headers->set('Content-Type', 'application/vnd.ms-excel');
$response->headers->set('Content-Disposition', 'attachment;filename="ArticlesPlateforme.xls"');
$response->headers->set('Cache-Control', 'max-age=0');
// If you're serving to IE 9, then the following may be needed
$response->headers->set('Cache-Control', 'max-age=1');
// If you're serving to IE over SSL, then the following may be needed
$response->headers->set('Expires', 'Mon, 26 Jul 2015 05:00:00 GMT'); // Date in the past
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s').' GMT'); // always modified
$response->headers->set('Cache-Control', 'cache, must-revalidate'); // HTTP/1.1
$response->headers->set('Pragma', 'public'); // HTTP/1.0
return $response;
}
public function generationExcelation(请求$Request)
{
/*
*设置时间限制,并在导出excel文本时设置超时。
*/
设置时间限制(0);
ini_集('内存限制','-1');
$this->getdoctor()->getConnection()->getConfiguration()->setSQLLogger(null);
/**@var\Nalods\Entity\article存储库$repoArticles*/
$repoArticles=$this->getDoctrine()->getRepository('Nalods\Entity\Article');
$requeteArticle=$repoArticles->findByPlateforme($this->getUser()->getPlateforme()->getId());
$filter=新的重新分配筛选器();
$filterForm=$this->createForm(
重新分配筛选器类型::类,
$filter,
[
“arbo'=>this->getArborescenceManager()->getArborescenceForReassort(),
'fournisseurs'=>this->getdoctor()->getRepository('Nalods\Entity\FournisseurCommun')->getfournisseursforresort($this->getUser()->getplatforme()->getId()),
]
);
$filterForm->HandlerRequest($request);
$requeteArticle=$repoArticles->applyFilter($requeteArticle,$filter,$request->getSession()->get(Commande::ID_SESSION));
$requeteArticle->select('DISTINCT a.id');
$listedarticle=$requeteArticle->getQuery()->getScalarResult();
$response=新的流响应();
$response->setCallback(函数()使用($listedarticles){
//新一代名人录
$objPHPExcel=new PHPExcel();
//在Excel中初始化les propriétédu classeur
$objPHPExcel->getProperties()->setCreator(“Nalod”)
->setLastModifiedBy(“Nalod的”)
->setTitle(“导出XLS”);
//科隆大酒店
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1','Code Centrale')
->setCellValue('B1','Désignation')
->setCellValue('C1','Gencod')
->setCellValue('D1','Réf Produit')
->setCellValue('E1','N°人造丝')
->setCellValue('F1','Rayon')
->setCellValue('G1','N°Famile')
->setCellValue('H1','Famile')
->setCellValue('I1','N°Sous famille')
->setCellValue('J1','Sous famille')
->setCellValue('K1','N°Gamme')
->setCellValue('L1','Unitéd'achat')
->setCellValue('M1','Unitéde vente')
->setCellValue('N1','Nombre UV/UA')
->setCellValue('O1','Colisage')
->setCellValue('P1','Appro Mini')
->setCellValue('Q1','Prix achat brut')
->setCellValue('R1','Remise magasin 1')
->setCellValue('S1','Remise magasin 2')
->setCellValue('T1','Remise magasin 3')
->setCellValue('U1','Remise magasin 4')
->setCellValue('V1','Remise magasin 5')
->setCellValue('W1','Pa网络无底端')
->setCellValue('X1','Prix achat Net')
->setCellValue('Y1','系数')
->setCellValue('Z1','Taux marge')
->setCellValue('AA1','Prix vente conseillé')
->setCellValue('AB1','Taux de TVA')
->setCellValue('AC1','Date Début Validité')
->setCellValue('AD1','Date Fin Validité')
->setCellValue('AE1','Date MAJ')
->setCellValue('AF1','N°Fourniseur')
->setCellValue('AG1','Caractéristiques')
->setCellValue('AH1','Marque')
->setCellValue('AI1','Montant\u ttc\u ecotaxe')
->setCellValue('AJ1','Montantécomobilier')
->setCellValue('AK1','Stock Disponsible');
$i=0;
$j=0;
$listeBatch=array();
$total=计数($listedarticles);
而($i<$total){
$listedbatch[]=$listedarticles[$i]['id'];
如果($j<50&&$i!=$total-1){
$j++;
}否则{
$repoArticles=$this->getDoctrine()->getRepository('Nalods\Entity\Article');
$requeteArticle=$repoArticles->findByPlateforme($this->getUser()->getPlateforme()->getId());
$requeteArticle->andWhere($requeteArticle->expr()->in('a.id',$listeBatch));
$ListArticles=$requeteArticle->getQuery()->getResult();
/**@var\Nalods\Entity\Article$Article*/
foreach($k=>$article){
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A')($i-$j+$k+2),$article->getId())
->setCellValue('B')($i-$j+$k+2),$article->getNom()
->setCellValue('C')($i-$j+$k+2),$article->getArticleGencod()->first()->getGencod()->GetCodeBarComplete())
->setCellValue('D')($i-$j+$k+2),$article->getArticlePlateforme()->first()->GetReferenceFurnisseur())
->setCellValue('E')($i-$j+$k+2),$article->getSousFamille()->getFamille()->getRayon()->getId())
->setCellValue('F')($i-$j+$k+2),$article->getSousFamille()->getFamille()->getRayon()->getlibelleplete())
->setCellValue('G')($i-$j+$k+2),$article->getSousFamille()->getFamille()->getId())
->setCellValue('H')($i-$j+$k+2),$article->getSousFamille()->getFamille()->getLibelleComplete())
->setCellValue('I')($I-$j+$k+2),$article->getSousFamille()->getId())
->setCellValue('J')($i-$J+$k+2),$article->getSousFamille()->getLibelleComplete())
->setCellValue('K')($i-$j+$K+2),$article->getGamme()
->setCellValue('L')($i-$j+$k+2),$article->getUniteAchatComplete())