1.配置controller
public void export(){ Map<String, String[]> searchMap = new HashMap<String,String[]>(getParaMap()); String sql = "select b.name,b.sex,b.card_number,b.address,b.lxdh,b.check_flag,b.sjly,d.value jflx,c.name jfdd,o.je,o.jfnf,o.lrr,o.create_time,e.value yhlx from zklt_sjjl o,zklt_id_card_info b,zklt_area c,sys_dct d,sys_dct e,sys_user f where o.sfzh=b.card_number and o.jfdd=c.id and o.jflx=d.key and b.yhlx=e.key and o.creater=f.id and d.group_id='82088c59e3584c27830c8a831d355150' and e.group_id='93bfd0284e0e47ddaf4f08f429b691d1' and f.status=1 and o.yxbs='1' and b.yxbs='1' and c.yxbs='1' "; String[] colCode =new String[] {"name","sex","card_number","address","jflx","jfdd","je","lrr","create_time","yhlx","lxdh","sjly"}; String[] colName = new String[] {"姓名","性别", "身份证号", "地址", "缴费类型", "缴费地点", "金额", "填报人", "填报日期", "备注","联系电话","数据来源","说明"}; File file = new File(ExcelExportUtil.getTitle()); file = ExcelExportUtil.saveFile(colCode,colName, sql, file); renderFile(file); } |
2.controller中使用的工具类:
import java.io.File; import org.apache.poi.hssf.usermodel.HSSFCell; import com.jfinal.kit.PathKit; public class ExcelExportUtil { //设置第2行第13列单元格的内容 |
3.页面HTML按钮
<form action="#(ctx)/admin/zklt/payInfo/export" method="post"> <div class="form-group"> <div class="col-md-3"> <label class="col-sm-5 control-label">缴费年份</label> <div class="col-sm-7"> <input type="text" id="ssnf" name="ssnf" value="#(ssnf?ssnf:'')" class="form-control" readonly="readonly" onFocus="WdatePicker({isShowClear:false,dateFmt:'yyyy',startDate:'%y'})"> </div> </div> </div> <div class="form-group"> <div class="col-md-3"> <label class="col-sm-5 control-label">身份证号</label> <div class="col-sm-7"> <input id="sfzh" name="sfzh" class="form-control" type="text"> </div> </div> </div> <div class="form-group"> <div class="col-md-9 text-right"> <button class="btn btn-mint" type="button" οnclick="refreshTable();"><i class="glyphicon glyphicon-search"></i> 搜索</button> <button class="btn btn-mint" type="submit"><i class="glyphicon glyphicon-arrow-up"></i> 导出</button> </div> </div> </form> |