当前位置 : 主页 > 网络编程 > PHP >

putputPHPExcel.txt

来源:互联网 收集:自由互联 发布时间:2021-06-28
putputPHPExcel.txt $arr){//默认第一行有列标题$i=0;foreach($arr as $k = $v) {$objPHPExcel-setActiveSheetIndex(0)-setCellValue(PHPExcel_Cell::stringFromColumnIndex($i).($j+1),$v);if($key==0){$objPHPExcel-setActiveSheetIndex(0)-setCel
putputPHPExcel.txt
  $arr){
		//默认第一行有列标题
		$i=0;
		foreach($arr as $k => $v) {
			$objPHPExcel->setActiveSheetIndex(0)->setCellValue(PHPExcel_Cell::stringFromColumnIndex($i).($j+1),$v);
			if($key==0){
			$objPHPExcel->setActiveSheetIndex(0)->setCellValue(PHPExcel_Cell::stringFromColumnIndex($i).$j,$k);
			}
			$i++;
		}
	$j++;
	}





//设置默认字体
$objPHPExcel->getDefaultStyle()->getFont()->setName( 'Arial');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(12);

//设置列宽
$objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(14);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
//设置居中
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
//excel保存在根目录下  如要导出文件,以下改为注释代码
//$objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
//$objPHPExcel-> setActiveSheetIndex(0);
//$objWriter = $iofactory -> createWriter($objPHPExcel, 'Excel2007');
//$objWriter -> save('SetExcelName.xlsx');
//导出代码
$objPHPExcel->getActiveSheet() -> setTitle('订单列表');
$objPHPExcel-> setActiveSheetIndex(0);

$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$filename = '会员列表.xlsx';
ob_end_clean();//清除缓存以免乱码出现
header('Content-Type: application/vnd.ms-excel');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter -> save('php://output');
	//echo  PHPExcel_Cell::columnIndexFromString('A');
?>
上一篇:ClientHelper.php
下一篇:swoole_mq.php
网友评论