导出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. 洛谷 P1606 [USACO07FEB]荷叶塘Lilypad Pond 解题报告

    P1606 [USACO07FEB]荷叶塘Lilypad Pond 题目描述 FJ has installed a beautiful pond for his cows' aesthetic enj ...

  2. margin-top影响父元素定位

    写样式时无意中发现margin-top会影响到父元素的定位,下面是示例: HTML代码: <div class="demo"> <div class=" ...

  3. HDU 1159 最长公共子序列(n*m)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  4. Download RPM packages from a YUM repo without installing

    This how-to will explain how to download rpm packages from a yum repository without installing them. ...

  5. 校内训练0602 习题exercise

    [题目大意] f(i)=((Af(i-1)+B)/(Cf(i-1)+D)) mod P. 给出f(0), A, B, C, D, P, n,求f(n). 多组数据T<=1e4 n<=1e1 ...

  6. Android ANR 详解

    ANR简介 ANR,是“Application Not Responding”的缩写,即“应用程序无响应”.在Android中,ActivityManagerService(简称AMS)和Window ...

  7. Extend Html.EditorFor MVC

    原文发布时间为:2011-09-07 -- 来源于本人的百度文章 [由搬家工具导入] http://aspadvice.com/blogs/kiran/archive/2009/11/29/Addin ...

  8. poj 1061 青蛙的约会 (扩展欧几里得模板)

    青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status ...

  9. [bzoj1001][BJOI2006]狼抓兔子——最大流转最短路,平面图

    题目描述: 给定一个平面图,求最小割. 题解: 本题是一道经典题. 周冬Orz的论文是很好的研究资料. 这道题点太多,所以直接跑dinic无疑会超时. 我们观察原图,发现原图是一个平面图. 什么是平面 ...

  10. shell脚本查看服务器基本信息

    #!/bin/sh #电脑概览 #电脑型号 ComputerModel=`/usr/bin/sudo /usr/sbin/dmidecode | grep -A2 "System Infor ...