数据导出Excel表格
2024-09-10 20:44:05
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';
}
}
});
}
最新文章
- [网站公告]数据库服务器IOPS跑满造成网站不能正常访问
- PHP类型转换
- RedHat 6.7 Enterprise x64环境下使用RHCS部署Oracle 11g R2双机双实例HA
- java利用透明的图片轮廓抠图
- 原生JS默认设置默认值的写法
- 一致性哈希(consistent hashing)算法
- Java API —— IO流(数据操作流 &; 内存操作流 &; 打印流 &; 标准输入输出流 &; 随机访问流 &; 合并流 &; 序列化流 &; Properties &; NIO)
- Git教程(10)git比较复杂的功能
- Idiomatic Python手记一: average in FP way
- ASP.Net 验证视图状态 MAC 失败
- Apple Catching(POJ 2385)
- ORA-01791: not a SELECTed expression 一种是不 bug 的 bug!
- 语言总结—C/C++
- face-alignment:用 pytorch 实现的 2D 和 3D 人脸对齐库
- Python学习笔记(Ⅱ)——循环/选择/函数
- 【立体几何】分类讨论很细节 Gym - 101967I Путешествие по тору
- 定义action的允许访问方式
- 一个linux bbr存在的调用顺序bug
- Extjs 在项目中碰到问题
- DeviceIOControl与驱动层 - 缓冲区模式
热门文章
- Transformer【Attention is all you need】
- blackbox_exporter介绍
- freetype 字形解析
- Rancher2.1安装部署
- WordPress Plugin Contact Form Builder [CSRF → LFI]
- flex弹性盒子的使用
- Apache Spark 章节1
- ubuntu系统的teamviewer的安装及使用
- Leetcode 992 Subarrays with K Different Integers
- Java Swing 编程 JComboBox 显示不全问题。