public String exportInfoFr(String path,String name,String startdate,String enddate,SysUser user){
List<Map<String, Object>> list = this.esEntPermitErrDao.findListObjectBySql("select 字段值1,字段值2,字段值3,字段值4,字段值5 from 表名 where 字段值2 in ('0','2')");
if (list.size()> && list != null ) {
try {
List<Map<String,Object>> redBlackMsg = null;
List<Map<String,Object>> temp = new ArrayList<>();
WritableWorkbook wwb = null;
wwb = Workbook.createWorkbook(new java.io.File(path));
int size = ;
WritableSheet wst = wwb.createSheet("sheet1", );
Label label2 = new Label(, , "类别");
Label label3 = new Label(, , "名称");
Label label4 = new Label(, , "社会");
Label label5 = new Label(, , "注册号");
Label label6 = new Label(, , "组织");
Label label7 = new Label(, , "登记号");
Label label8 = new Label(, , "单位"); wst.addCell(label2);
wst.addCell(label3);
wst.addCell(label4);
wst.addCell(label5);
wst.addCell(label6);
wst.addCell(label7);
wst.addCell(label8); for (int i = ; i < list.size(); i++) {
Map map = (Map) list.get(i);
wst.addCell(new Label(,i+,(String)map.get("字段值1")));
wst.addCell(new Label(,i+,(String)map.get("字段值2")));
wst.addCell(new Label(,i+,(String)map.get("字段值3")));
if (map.get("字段值4")!=null && !map.get("字段值4").equals("")) {
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
wst.addCell(new Label(,i+,sdf.format((Date)map.get("字段值4"))));
}
wst.addCell(new Label(,i+,(String)map.get("字段值5")));
}
wwb.write();
wwb.close();
} catch (Exception e) {
e.printStackTrace();
}
return name;
}else {
return "";
}
}

导入的包

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

action中

    /**创建excle*/
public String creatExcle(String tooldataid){
FileUtil fileUtil = new FileUtil();
String path=this.getRequest().getRealPath("/")+"/upload/downxls/download/"+tooldataid+".xls";
fileUtil.createFile(path);
return path;
}
    /**导出筛查信息*/
public void exportScreenInfoFr(){
String name = String.valueOf(System.currentTimeMillis());
String startdate = this.getParameterToPage("startdate");
String enddate = this.getParameterToPage("enddate");
if (!startdate.equals("") && !enddate.equals("")) {
startdate += " 00:00:00";
enddate += " 23:59:59";
}
SysUser user = this.sysUserManager.getById(this.getCurrentSessionUser().getUserId());
this.ajaxText(esEntPermitErrManager.exportInfoFr(creatExcle(name),name,startdate,enddate,user));
}

jsp页面

<a href="#" onclick="exportInfoFr()" class="btn">导出</a>
   //导出信息
function exportInfoFr(){
var startdate = $("input[name='startdate']").val();
var enddate = $("input[name='enddate']").val();
$.ajax({
url : '${root}/df/PermErr/exportScreenInfoFr.do',
cache : false,
async : true,
type : "POST",
data :{startdate:startdate,enddate:enddate},
dataType:"text",
success : function(data) {
if(data==""){
errorTip("没有筛查数据!");
}else{
window.location='${root}/servlet/dfile?fileName='+data+'.xls&path=upload/downxls/download';
}
}
});
}

最新文章

  1. [网站公告]数据库服务器IOPS跑满造成网站不能正常访问
  2. PHP类型转换
  3. RedHat 6.7 Enterprise x64环境下使用RHCS部署Oracle 11g R2双机双实例HA
  4. java利用透明的图片轮廓抠图
  5. 原生JS默认设置默认值的写法
  6. 一致性哈希(consistent hashing)算法
  7. Java API —— IO流(数据操作流 &amp; 内存操作流 &amp; 打印流 &amp; 标准输入输出流 &amp; 随机访问流 &amp; 合并流 &amp; 序列化流 &amp; Properties &amp; NIO)
  8. Git教程(10)git比较复杂的功能
  9. Idiomatic Python手记一: average in FP way
  10. ASP.Net 验证视图状态 MAC 失败
  11. Apple Catching(POJ 2385)
  12. ORA-01791: not a SELECTed expression 一种是不 bug 的 bug!
  13. 语言总结—C/C++
  14. face-alignment:用 pytorch 实现的 2D 和 3D 人脸对齐库
  15. Python学习笔记(Ⅱ)——循环/选择/函数
  16. 【立体几何】分类讨论很细节 Gym - 101967I Путешествие по тору
  17. 定义action的允许访问方式
  18. 一个linux bbr存在的调用顺序bug
  19. Extjs 在项目中碰到问题
  20. DeviceIOControl与驱动层 - 缓冲区模式

热门文章

  1. Transformer【Attention is all you need】
  2. blackbox_exporter介绍
  3. freetype 字形解析
  4. Rancher2.1安装部署
  5. WordPress Plugin Contact Form Builder [CSRF → LFI]
  6. flex弹性盒子的使用
  7. Apache Spark 章节1
  8. ubuntu系统的teamviewer的安装及使用
  9. Leetcode 992 Subarrays with K Different Integers
  10. Java Swing 编程 JComboBox 显示不全问题。