首页 > 代码库 > 导出excel终结版
导出excel终结版
////////////html/////////
<form method="post" action="{:u(‘order_fengqiang/index‘)}" >
<table width="100%" cellspacing="0" class="search_form">
<tbody>
<tr>
<td>
<div class="explain_col">
<input type="hidden" name="g" value="http://www.mamicode.com/admin" />
<input type="hidden" name="m" value="http://www.mamicode.com/item_order" />
<input type="hidden" name="a" value="http://www.mamicode.com/index" />
<input type="hidden" name="menuid" value="http://www.mamicode.com/{$menuid}" />
订单编号 :
<input name="orderId" type="text" class="input-text" size="25" id="orderId" value="http://www.mamicode.com/{$orderId}" />
真实姓名 :
<input name="truename" type="text" class="input-text" size="25" id="truename" value="http://www.mamicode.com/{$truename}" />
订单状态 :
<select name="status" id="status" value="http://www.mamicode.com/{$status}">
<option value="http://www.mamicode.com/0" <if condition="$status eq 5 ">selected</if>>--所有--</option>
<option value="http://www.mamicode.com/1" <if condition="$status eq 1 ">selected</if>>--待发货--</option>
<option value="http://www.mamicode.com/2" <if condition="$status eq 2 ">selected</if>>--已发货--</option>
<option value="http://www.mamicode.com/3" <if condition="$status eq 3 ">selected</if>>--待收货--</option>
<option value="http://www.mamicode.com/4" <if condition="$status eq 4 ">selected</if>>--完成--</option>
<!-- <option value="http://www.mamicode.com/4" <if condition="$status eq 4 ">selected</if>>--完成--</option> -->
</select>
<br>
<if condition="$sm neq ‘‘"><input type="hidden" name="sm" value="http://www.mamicode.com/{$sm}" /></if>
下单时间 :
<input type="text" name="time_start" id="J_time_start" class="date" size="12" value="http://www.mamicode.com/{$time_start}">
-
<input type="text" name="time_end" id="J_time_end" class="date" size="12" value="http://www.mamicode.com/{$time_end}">
<input type="submit" name="search" class="btn" value="http://www.mamicode.com/搜索" />
</div>
</td>
</tr>
</tbody>
</table>
<!-- <a href="http://www.mamicode.com/#" target="_blank" class="btn" onclick="execl()">导出Execl表</a> -->
<!-- <a href="http://www.mamicode.com/{:U(‘order_fengqiang/pro‘)}" target="_blank" class="btn ">导出Execl表</a> -->
<input type="button" value="http://www.mamicode.com/导出Execl表" onclick="outData()" class="btn ">
</form>
///////////js/////////////
<script>
function outData(){
Data=http://www.mamicode.com/{
time_start:$("#J_time_start").val(),
time_end:$("#J_time_end").val(),
truename:$("#truename").val(),
orderId:$("#orderId").val(),
status:$("#status").val()
};
$.ajax({
type: "POST",
url: "{:U(‘order_fengqiang/pro‘)}",
data:Data,
beforeSend:function(){
layer.load(‘正在积极导出中‘,3);
},
success: function(msg){
location.href=http://www.mamicode.com/msg;
},
})
}
</script>
//////php////////////
public function pro(){
if($_POST[‘time_start‘]&&$_POST[‘time_end‘]){
$where[‘item_order.add_time‘] = array(array(‘egt‘, strtotime($_POST[‘time_start‘])),array(‘elt‘, strtotime($_POST[‘time_end‘])+(24*60*60-1))) ;
}
if($_POST[‘status‘]){
if($_POST[‘status‘]!==‘0‘){
$where[‘item_order.status‘]=$_POST[‘status‘];
}
}
if($_POST[‘orderId‘]){
/* $where=" order_detail.orderId=‘".$_POST[‘orderId‘]."‘"; */
$where[‘order_detail.orderId‘]=$_POST[‘orderId‘];
}
if($_POST[‘truename‘]){
$where[‘user.truename‘]=$_POST[‘truename‘];
/* $where.="and user.truename=‘".$_POST[‘truename‘]."‘"; */
}
$where[‘order_sumPrice‘]=0;
if($_POST[‘orderId‘]!==""||$_POST[‘truename‘]!==""||$_POST[‘status‘]!==""||$_POST[‘time_start‘]!==""||$_POST[‘time_end‘]!==""){
$ProList=D(‘FengqiangView‘)->where($where)->select();
}else{
$ProList=D(‘FengqiangView‘)->where("order_sumPrice =‘0‘")->select();
}
vendor(‘PHPExcel‘);
$objPHPExcel = new PHPExcel();
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_wincache;
$cacheSettings = array( ‘cacheTime‘ => 600 );
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue(‘A1‘, ‘订单ID‘)
->setCellValue(‘B1‘, ‘用户名‘)
->setCellValue(‘C1‘, ‘订单编号‘)
->setCellValue(‘D1‘, ‘联系方式‘)
->setCellValue(‘E1‘, ‘下单时间‘)
->setCellValue(‘F1‘, ‘商品‘)
->setCellValue(‘G1‘, ‘收货地址‘);
$objPHPExcel->getActiveSheet()->getStyle(‘C1‘)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle(‘D1‘), ‘E5:E13‘ );
if($ProList){
for($count = 0;$count<count($ProList); $count++){
$row = $count + 2;
$objPHPExcel->getActiveSheet()->setTitle(‘Simple‘);
(string)$objPHPExcel->setActiveSheetIndex(0)
->setCellValue(‘A‘.$row, $ProList[$count][‘id‘])
->setCellValue(‘B‘.$row, $ProList[$count][‘truename‘])
->setCellValue(‘C‘.$row, ‘ ‘.$ProList[$count][‘orderId‘])
->setCellValue(‘D‘.$row, ‘ ‘.$ProList[$count][‘tel‘])
->setCellValue(‘E‘.$row, date ( ‘Y-m-d H:i:s‘, $ProList[$count][‘add_time‘]))
->setCellValue(‘F‘.$row, $ProList[$count][‘intro‘])
->setCellValue(‘G‘.$row, $ProList[$count][‘address‘]);
}
}
/**
* 设置宽度
*/
$objPHPExcel->getActiveSheet()->setTitle(‘免费疯抢订单表‘);
/* $objPHPExcel->getActiveSheet()->getColumnDimension(‘B‘)->setAutoSize(true); */
$objPHPExcel->getActiveSheet()->getColumnDimension(‘A‘)->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘B‘)->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘C‘)->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘D‘)->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘E‘)->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘F‘)->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension(‘G‘)->setWidth(60);
/**
*设置样式居中
*/
$objPHPExcel->getActiveSheet()->getStyle(‘A‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(‘B‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(‘C‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(‘D‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(‘E‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(‘F‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(‘G‘)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel5‘);
$return=$objWriter->save(‘Pro_List.xls‘);
import("ORG.Tools");
if(isset($return)){
Tools::getBack("导出失败", 2);
}else{
$url="http://".$_SERVER[HTTP_HOST].__ROOT__."/Pro_List.xls";
/* echo "<script>location.href=http://www.mamicode.com/‘".$url."‘;</script>"; */
echo $url;
}
}