//xls格式下载 set_time_limit(0); $line_num = 1; $resultPHPExcel = new PHPExcel(); $resultPHPExcel->getActiveSheet()->setCellValue("A1", ‘业务参考号‘); $resultPHPExcel->getActiveSheet()->getColumnDimension(‘A‘)->setWidth(10); //设置单元格宽度 $resultFillA1 = $resultPHPExcel->getActiveSheet()->getStyle("A1")->getFill("A1");//颜色 $resultFillA1->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $resultPHPExcel->getActiveSheet()->setCellValue("B1", ‘收款人编号‘); $resultPHPExcel->getActiveSheet()->getColumnDimension(‘B‘)->setWidth(10); //设置单元格宽度 $resultFillA1 = $resultPHPExcel->getActiveSheet()->getStyle("B1")->getFill("B1");//颜色 $resultFillA1->setFillType(PHPExcel_Style_Fill::FILL_SOLID); //字体加粗 $resultPHPExcel->getActiveSheet()->getStyle(‘A1:B1‘)->getFont()->setBold(true); //居中 $resultPHPExcel->getActiveSheet()->getStyle(‘A1:B1‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $outputFileName = date(‘Y年m月d日 H时i分‘,time()) . ‘合同信息下载.xls‘; //每次取数据的步进 $step = 1000; $round = ceil($count / $step); for ($i = 1; $i <= $round; $i++) { $criteria->limit = $step; //取1条数据,如果小于0,则不作处理 $criteria->offset = ($i - 1) * $step; //两条合并起来,则表示 limit 10 offset 1,或者代表了。limit 1,10 $rent_contract_list = T_rent_contract::model()->findAll($criteria); if (count($rent_contract_list)) { foreach ($rent_contract_list as $rent_contract) { $line_num++; $resultPHPExcel->getActiveSheet()->setCellValue("A{$line_num}",$content_a); $resultPHPExcel->getActiveSheet()->setCellValue("B{$line_num}",content_b); //$resultPHPExcel->getActiveSheet()->setCellValueExplicit("C{$line_num}", $rent_contract->f_rent_number,PHPExcel_Cell_DataType::TYPE_STRING); //银行卡账号,防止导出到excel后数据格式不对 } } } define(‘PHPEXCEL_ROOT‘, dirname(__FILE__)); require_once PHPEXCEL_ROOT . ‘PHPExcel/Writer/Excel5.php‘; $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header(‘Content-Disposition:inline;filename="‘ . $outputFileName . ‘"‘); 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"); $xlsWriter->save("php://output"); exit;
时间: 2024-11-03 09:27:51