导出Excel功能分sheet页处理数据:

/*导出EXCEL*/
public void createExcel() {
log.info("导出Excel功能已经启动-BEGIN");
JxlUtil jsl = new JxlUtil();
List<Device> dataList =new ArrayList<Device>();
List<DeviceExport> list = new ArrayList<DeviceExport>();
// 构建路径
String downLoadPath = "/WEB-INF/download/asset/";
String rootPath = getServletContext().getRealPath(downLoadPath); String fileName = "";
File file=new File(rootPath); try {
if(!(file.exists()||file.isDirectory())){
file.mkdirs();
} if (null != getRequest().getParameter("ids")) {
String ids[] = getRequest().getParameter("ids").split(",");
for (int i = ; i < ids.length; i++) {
if(null!=ids[i]){
device = deviceService.queryById(ids[i].trim());
dataList.add(device);
}
}
}else{
dataList = deviceService.queryForExcel();
} if(dataList!=null){
for (Device device : dataList) {
DeviceExport deviceExport= new DeviceExport();
if(null!=device.getId()){
deviceExport.setId(device.getId());
}
if(null!=device.getIp()){
deviceExport.setIp(device.getIp());
}
if(null!=device.getMac()){
deviceExport.setMac(device.getMac());
}
if(null!=device.getName()){
deviceExport.setName(device.getName());
}
if(null!=device.getOrganization()){
Organization organization=device.getOrganization();
String Aname =organization.getName();
String name= getAname(organization, Aname);
deviceExport.setOrganizationName(name);
}
if(null!=device.getRegState()){
deviceExport.setRegState(device.getRegState());
}
if(null!=device.getUser()){
deviceExport.setUserName(device.getUser().getName());
}
if(null!=device.getProtectState()){
deviceExport.setProtectState(device.getProtectState());
}
if(null!=device.getIsOpened()){
deviceExport.setIsOpened(device.getIsOpened());
}
String osName = MessageUtils.getMessage(device.getOs().getName());
deviceExport.setOsName(osName);
String deviceType = MessageUtils.getMessage(device.getDeviceType().getName());
deviceExport.setDeviceTypeName(deviceType);
list.add(deviceExport);
}
} String interBase = "sys.column.name.device";
//String inter_value_key = "#isOpened#roamState#protectState#";
String inter_value_key = "#isOpened#protectState#regState#";
String[] inter_value_ary = { "isOpened.0", "isOpened.1", "protectState.0", "protectState.1","regState.0","regState.1"};
//导出不显示漫游状态
//String[] inter_value_ary = { "isOpened.0", "isOpened.1","roamState.0", "roamState.1","protectState.0", "protectState.1"}; fileName = jsl.getInter(interBase.replace("column", "table"))
+ new Date().getTime();
String targetfile = rootPath + System.getProperty("file.separator")
+ fileName + ".xls"; //分sheet页处理
int total = dataList.size();//总数
int max = ;//每sheet页允许最大数
int avg = total / max;//sheet页个数 // 创建可写入的Excel工作薄
WritableWorkbook wwb;
wwb = Workbook.createWorkbook(new File(targetfile)); for(int i=;i<avg+;i++){
// 创建Excel工作表
WritableSheet ws = wwb.createSheet("已注册设备"+(i+), i);
int num = i * max;
int index = ;
List<DeviceExport> exportList = new ArrayList<DeviceExport>();
for(int m = num; m < total; m++){//m即为每个sheet页应该开始的数
if(index == max){//判断 index = max 的时候跳出里层的for循环
break;
}
DeviceExport deviceExport=list.get(m);
exportList.add(deviceExport);//从总的list数据里面取出该处于哪个sheet页的数据,然后加进exportList,exportList即为当前sheet页应该有的数据
index++;
}
// 获取需要内容国际化的字段
jsl.creatDeviceExcel(ws, exportList, interBase, inter_value_key,inter_value_ary);
} // 写入Exel工作表
wwb.write();
// 关闭Excel工作薄对象
wwb.close(); getResponse().setContentType(getServletContext().getMimeType(fileName));
getResponse().setHeader("Content-Disposition", "attachment;fileName="+new String(fileName.getBytes("gb2312"), "ISO8859-1")+".xls");
String fullFileName = getServletContext().getRealPath(downLoadPath + fileName+ ".xls");
InputStream in = new FileInputStream(fullFileName);
OutputStream out = getResponse().getOutputStream();
int b;
while((b=in.read())!= -){
out.write(b);
}
in.close();
out.close();
/*ServletActionContext.getRequest().setAttribute("downLoadPath",
downLoadPath);
ServletActionContext.getRequest().setAttribute("fileName",
fileName + ".xls");*/
this.msg = RESULT_SUCCESS;
log.info("导出EXCEL提示信息为:"+this.msg);
} catch (Exception e) {
log.error("导出EXCEL失败:" + e.getMessage());
}
log.info("导出Excel功能已经启动-END");
/*return "downLoadUI";*/
}

  导出效果如下:

项目笔记:导出Excel功能分sheet页插入数据的更多相关文章

  1. 公司项目笔记-导出excel

    一.asp.net中导出Excel的方法: 在asp.net中导出Excel有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出流写给浏览 ...

  2. 项目笔记:导出Excel功能

    1.前台这块: var ids=""; $.post("${basePath}/assets/unRegDeviceAction_getDeviceIds.do" ...

  3. vue项目导出EXCEL功能

    因为一些原因导出EXCEL功能必须前端来做,所以就研究了一下,在网上也找了一些文章来看,有一些不完整,我做完了就记录下来,供大家参考: 1.首先先安装依赖: npm install file-save ...

  4. Vue通过Blob对象实现导出Excel功能

    不同的项目有不同的导出需求,有些只导出当前所显示结果页面的表格进入excel,这个时候就有很多插件,比如vue-json-excel或者是Blob.js+Export2Excel.js来实现导出Exc ...

  5. Atitit.导出excel功能的设计 与解决方案

    Atitit.导出excel功能的设计 与解决方案 1.1. 项目起源于背景1 1.2. Js  jquery方案(推荐)jquery.table2excel1 1.3. 服务器方案2 1.4. 详细 ...

  6. CRM 报表导出excel时指定sheet名

    如图所示,设置PageName即可: 这样导出excel时,sheet的名就有了:

  7. 多张报表导出到一个多sheet页excel

     业务需求: 通过勾选不同的报表名称,然后直接执行导出excel.并且这些报表需要统一导入到一个excel的多个sheet页中,并且对某些报表可能需要增加一些类似'已审核'之类的图片(展现时并没有 ...

  8. 【angularjs】pc端使用angular搭建项目,实现导出excel功能

    此为简单demo. <!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset= ...

  9. spring mvc项目中导出excel表格简单实现

    查阅了一些资料,才整理出spring mvc 项目导出excel表格的实现,其实很是简单,小计一下,方便以后查阅,也希望帮助有需要的朋友. 1.导入所需要依赖(Jar包).我使用的是maven,所以坐 ...

随机推荐

  1. Tomcat源码浅析

    最近在学习tomcat源码,算是把tomcat的整个流程梳理通了. 从上图来看,tomcat把模块化使用到了极致,配合组件生命周期的管理,让代码看起来结构清晰,而且很容易进行业务扩展. 1.上图的接口 ...

  2. 在Linux上录制终端的操作

    在Linux上录制终端的操作 来源 http://blog.51cto.com/stuart/1831570 一.安装基础软件包 1 [root@test software]# yum install ...

  3. Java 虚拟机类加载机制

    看到这个题目,很多人会觉得我写我的java代码,至于类,JVM爱怎么加载就怎么加载,博主有很长一段时间也是这么认为的.随着编程经验的日积月累,越来越感觉到了解虚拟机相关要领的重要性.闲话不多说,老规矩 ...

  4. 洛谷 P2916 [USACO08NOV]为母牛欢呼Cheering up the C…

    题目描述 Farmer John has grown so lazy that he no longer wants to continue maintaining the cow paths tha ...

  5. 关于JSON的简介及取值以及常见面试题

    关于JSON的简介及取值 JSON(JavaScript Object Notation)一种轻量级的数据交互格式 类似于一种数据封装,可以想象为java中student封装类 JSON的数值可以是数 ...

  6. centos 下文件夹共享

    [root@localhost share]# yum install samba -y[root@localhost share]# cp /etc/samba/smb.conf /etc/samb ...

  7. qfish/Bee-Xcode-Template

    https://github.com/qfish/Bee-Xcode-Template Bee-Xcode-Template Xcode Template for BeeFramework. You ...

  8. 报告撰写,linux使用gimp简单做gif动图

    我想把我的系统菜单完整记录下来,方便查看,如果单纯使用文字比较单调,使用屏幕截图,需要依次打开多个图像查看也不是很方便,就想到了使用动画的形式展示.由于本人的系统一直使用Linux系统,为了一张gif ...

  9. 《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---47

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  10. Centos 查看进程的几条命令

    1. ps -ef | grep java 表示查看所有进程里 CMD 是 java 的进程信息 2. ps -aux | grep java -aux 显示所有状态 3. kill -9 [PID] ...