当前位置:Gxlcms > PHP教程 > 关于PHPEXCEL输出表格有上万条记录的时候貌似挂了

关于PHPEXCEL输出表格有上万条记录的时候貌似挂了

时间:2021-07-01 10:21:17 帮助过:18人阅读

关于PHPEXCEL输出报表有上万条记录的时候貌似挂了?
这是一个完整可用的phpexcel例子
require('includes/application_top.php');
error_reporting(E_ALL);
set_include_path(get_include_path() . PATH_SEPARATOR . 'classes/');//設置路徑

include 'PHPExcel/PHPExcel.php';
include 'PHPExcel/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->freezePane('A2');
$sharedStyle1 = new PHPExcel_Style();
$sharedStyle1->applyFromArray(
array('fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'FFCCFFCC')
),
'borders' => array(
'bottom'=> array('style' => PHPExcel_Style_Border::BORDER_THIN),
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
)
));
$sharedStyle2 = new PHPExcel_Style();
$sharedStyle2->applyFromArray(
array('fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'fff4f4f4')
)
));
$objPHPExcel->getActiveSheet()->setSharedStyle($sharedStyle1, "A1:O1");

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(50);

$objPHPExcel->getActiveSheet()->setTitle('Student Export');//設置當前工作表的名稱
for($i=0;$i<15;$i++){
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($i, 1)->getFont()->setBold(true);//設置第一行內容加粗
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1,'First Name');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1,'Last Name');

人气教程排行