PHP 导出Excel示例分享_php技巧_脚本之家

下载PHPExcel_1.8.0_doc.zip

导出文件Excel.php

require_once dirname.'/Classes/PHPExcel.php';//引入PHPExcel.....此处略去从数据库获取数据的过程,$a为需要导出的数组......$numArr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');// Create new PHPExcel object$objPHPExcel = new PHPExcel();$arr = array('订单号','下单时间','城市','地区', '客户名称', '收货人', '联系电话', '收货地址', 'ERP客户名称', '物流系统客户名称', '活动项目', '品牌', '型号', '颜色', '物流系统型号', '订货量', '单价', '代收货款', '红包', '价保返利', '运费', '实收金额', '付款方式', '订单来源', '上游厂商', '是否在仓', '快递面单号', '订单状态', '确认时间', '末次状态确认时间', '描述', '对应业务', '对应客服', '商家留言', '下单摘要', '业务员', '联系方式');// 输出标题echo date , " Add some data" , EOL;//设置换行$objPHPExcel->getActiveSheet->getAlignment;$objPHPExcel->getActiveSheet->getAlignment;//设置相应列的宽度$objPHPExcel->setActiveSheetIndex->getColumnDimension;$objPHPExcel->setActiveSheetIndex->getColumnDimension;$objPHPExcel->setActiveSheetIndex->getColumnDimension;$objPHPExcel->setActiveSheetIndex->getColumnDimension;$objPHPExcel->setActiveSheetIndex->getColumnDimension;$objPHPExcel->setActiveSheetIndex->getColumnDimension;//输出第一行$objPHPExcel->setActiveSheetIndex ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue ->setCellValue;//输出内容for;$i++){ $objPHPExcel->setActiveSheetIndex ->setCellValue, $a[$i]['order_sn']) ->setCellValue, $a[$i]['add_time']) ->setCellValue, $a[$i]['city']) ->setCellValue, $a[$i]['region_name']) ->setCellValue, $a[$i]['company']) ->setCellValue, $a[$i]['consignee']) ->setCellValue, $a[$i]['mobile']) ->setCellValue, $a[$i]['address']) ->setCellValue, '') ->setCellValue, '') ->setCellValue, '') ->setCellValue, $a[$i]['brand_name']);}// Rename worksheetecho date , " Rename worksheet" , EOL;$dirName = date;//目录名$fileName = date;//文件名$objPHPExcel->getActiveSheet()->setTitle;// Set active sheet index to the first sheet, so Excel opens this as the first sheet$objPHPExcel->setActiveSheetIndex;// Save Excel 2007 fileecho date , " Write to Excel2007 format" , EOL;$callStartTime = microtime;if(!opendir){ mkdir;}$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save('../excel/'.$dirName.'/'.$fileName.'.xlsx');$end = getCurrentTime();$spend = $end-$begin;if { echo 'if{ window.history.back;}'; exit;}header('Location:http://'.$_SERVER['HTTP_HOST'].'/excel/'.$dirName.'/'.$fileName.'.xlsx');
You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图