• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-22) 16次浏览 已收录 0个评论

这是一个完整可用的phpexcel例子

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')->set<div>本文#来源gaodai.ma#com搞##代!^码7网</div><pre>搞代gaodaima码

Width(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;$igetActiveSheet()->getStyleByColumnAndRow($i, 1)->getFont()->setBold(true);//?置第一行?容加粗}$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1,'First Name');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1,'Last Name');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 1,'Date of Birth');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, 1,'Attendance Year');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, 1,'Course studied');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, 1,'Agency Booking / Direct Booking');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, 1,'Student Country');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, 1,'Student City');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, 1,'Student Home phone number');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, 1,'Student Mobile phone number');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, 1,'Student Email address');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, 1,'Emergency contact Name');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, 1,'Emergency contact phone number 1');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(13, 1,'Emergency contact phone number 2');$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(14, 1,'Order Date');$number=1;$orderdate='';$firstname='';$lastname='';$dateodbirth='';$attenddance='';$studied='';$booking='';$country='';$city='';$home_phone='';$mobile_phone='';$email='';$emer_name='';$emer_phone1='';$emer_phone2='';$sql="select orders_id,date_purchased from orders order by orders_id desc";$query=mysql_query($sql);while($arr=mysql_fetch_array($query)){ $number++; $orderdate=$arr['date_purchased']; $sql2="select * from orders_extra_info where orders_id='".$arr['orders_id']."'"; $query2=mysql_query($sql2); $num2=mysql_num_rows($query2); if($num2>0){ $arr2=mysql_fetch_array($query2); $firstname=$arr2['first_name']; $lastname=$arr2['last_name']; $dateodbirth=$arr2['date_of_birth']; $attenddance=$arr2['o_attendaceyear']; $booking=$arr2['o_agency']; if($booking==1){$booking='Direct Sale';} if($booking==2){$booking='Agent Sale';} $country_id=$arr2['country']; $city=$arr2['city']; $home_phone=$arr2['phone1']; $mobile_phone=$arr2['phone2']; $email=$arr2['email']; $emer_name=$arr2['emc_name']; $emer_phone1=$arr2['emc_phone1']; $emer_phone2=$arr2['emc_phone2']; $cou_sql="select countries_id,countries_name from countries where countries_id='".$country_id."'"; $con_query=mysql_query($cou_sql); $con_arr=mysql_fetch_array($con_query); $country=$con_arr['countries_name']; } $sql3="select products_name,orders_id from orders_products where orders_id='".$arr['orders_id']."'"; $query3=mysql_query($sql3); $num3=mysql_num_rows($query3); if($num3>0){ $studied=''; while($arr3=mysql_fetch_array($query3)){ $studied.=$arr3['products_name'].","; } $studied=substr($studied,0,strlen($studied)-1); } $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $number,$firstname); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $number,$lastname); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $number,$dateodbirth); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $number,$attenddance); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $number,$studied); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $number,$booking); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $number,$country); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $number,$city); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $number,$home_phone); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $number,$mobile_phone); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $number,$email); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, $number,$emer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, $number,$emer_phone1); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(13, $number,$emer_phone2); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(14, $number,$orderdate);}$objPHPExcel->setActiveSheetIndex(0);//?置打?excel??示哪?工作表$excelName = 'Student_Export'.date("YmdHis").'.xls';//?置?出excel的文件名$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');header("Content-Type: application/force-download");header("Content-Type: application/octet-stream");header("Content-Type: application/download");header("Content-Disposition: attachment; filename=".urlencode($excelName));header("Content-Transfer-Encoding: binary");header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header("Pragma: no-cache");$objWriter->save('php://output');require(DIR_WS_INCLUDES . 'application_bottom.php');?>


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于PHPEXCEL输出报表有上万条记录的时候貌似挂了?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址