当使用php服务器将mysql表导出到.xls文件时,速度变慢,导出的文件崩溃

xn1cxnb4  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(264)

我在mysql数据库中有一个表,有20列和1000000行。我尝试用phpexcel将它导出到.xls文件中,但是它会减慢系统的速度,并且导出的文件已损坏。请帮助我用php导出它。

set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);

$Qry= $con -> query("SELECT * FROM `table_1`");
$fn="excel_report";
$rowCount = 1;
$objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount,'COL 1')->getStyle('A'.$rowCount)->applyFromArray($headerColor);
$objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount,'COL 2')->getStyle('B'.$rowCount)->applyFromArray($headerColor);
$objPHPExcel->getActiveSheet()->SetCellValue('C'.$rowCount,'COL 3')->getStyle('C'.$rowCount)->applyFromArray($headerColor);
$objPHPExcel->getActiveSheet()->SetCellValue('D'.$rowCount,'COL 4')->getStyle('D'.$rowCount)->applyFromArray($headerColor);
$objPHPExcel->getActiveSheet()->SetCellValue('E'.$rowCount,'COL 5')->getStyle('E'.$rowCount)->applyFromArray($headerColor);
while($row=$Qry->fetch_array()){
$rowCount++;
$col_1=$row['col_1'];
$col_2=$row['col_2'];
$col_3=$row['col_3'];
$col_4=$row['col_4'];
$col_5=$row['col_5'];
$objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $col_1)->getStyle('A'.$rowCount)->applyFromArray($allBorder);
$objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $col_2)->getStyle('B'.$rowCount)->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->SetCellValue('C'.$rowCount, $col_3)->getStyle('C'.$rowCount)->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->SetCellValue('D'.$rowCount, $col_4)->getStyle('D'.$rowCount)->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->SetCellValue('E'.$rowCount, $col_5)->getStyle('E'.$rowCount)->getAlignment()->setWrapText(true);
}
$sheet = $objPHPExcel->getActiveSheet();
$cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
$cellIterator->setIterateOnlyExistingCells( true );
foreach( $cellIterator as $cell ) {
$sheet->getColumnDimension( $cell->getColumn() )->setAutoSize( true );
$sheet->getStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$sheet->getStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题