- 浏览: 429407 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
sunwang810812:
万分感谢中!!!!!这么多年终于看到一个可运行可解决的方案!! ...
POI 后台生成Excel,在前台显示进度 -
zzb7728317:
LZ正解
Spring Jackson AjaxFileUpload 没有执行回调函数的解决办法 -
sleeper_qp:
lz是在源码上修改的么? 源码的话你重新编译一遍了么? 可 ...
由nutch readseg -dump 中文编码乱码想到的…… -
shenjian430:
请问你改好的程序在写在哪了?
由nutch readseg -dump 中文编码乱码想到的…… -
yinxusen:
It seems to be the bug occur in ...
Mahout Local模式 执行example的注意点
使用Apache POI和DWR
poi用于在后台生成Excel,用DWR在前台显示后台生成Excel的进度
基本的生成Excel类:
ExcelHelper.java
public class ExcelHelper extends Thread{ private int rowIndex=0; private int count; private String fileName; private String sheetName; private List<String[]> dataList; public ExcelHelper(String fileName, String sheetName, List<String[]> dataList) { this.fileName = fileName; this.sheetName = sheetName; this.dataList = dataList; this.count=dataList.size(); } @Override public void run() { try { if (rowIndex==0) { generateWorkbook(); } } catch (IOException e) { e.printStackTrace(); } } /** * 生成Excel文件 * * @param fileName * 要生成的Excel文件名(可用绝对或相对路径) * @param sheetName * 生成的Excel文件中的sheet名 * @param dataList * 要放入Excel文件的内容 * @throws IOException */ public void generateWorkbook() throws IOException { Workbook wb = null; if (fileName.endsWith(".xlsx")) { wb = new XSSFWorkbook(); } else if (fileName.endsWith(".xls")) { wb = new HSSFWorkbook(); } else { fileName = fileName.concat(".xls"); wb = new HSSFWorkbook(); } CellStyle cellStyle = wb.createCellStyle(); Font font = wb.createFont(); font.setColor(HSSFColor.RED.index); cellStyle.setFont(font); Sheet sheet = wb.createSheet(sheetName); rowIndex = 0; for (String[] rowData : dataList) { Row row = sheet.createRow(rowIndex); rowIndex++; int cellIndex = 0; for (String cellData : rowData) { Cell cell = row.createCell(cellIndex); cell.setCellValue(cellData); cell.setCellStyle(cellStyle); cellIndex++; } } FileOutputStream fileOut = new FileOutputStream(fileName); wb.write(fileOut); fileOut.close(); } public int getRowIndex() { return rowIndex; } public int getCount() { return count; } }
DWR操作类:
ExcelHelperDWR.java
public class ExcelHelperDWR { private static Map<Long, ExcelHelper> excelHelperMap; public ExcelHelperDWR() { if (excelHelperMap == null) { excelHelperMap = new HashMap<Long, ExcelHelper>(); } } public int getRowIndex(long threadId) { ExcelHelper excelHelper = excelHelperMap.get(threadId); if (excelHelper.getRowIndex()<excelHelper.getCount()) { return excelHelper.getRowIndex(); }else { return -1; } } public long beginProcess(String fileName, String sheetName) { //test case List<String[]> dataList = new ArrayList<String[]>(); for (int i = 0; i < 1000; i++) { dataList.add(new String[] { "1", "2612601001", "学生1", "123", "3", null, "", "13712345678" }); dataList.add(new String[] { "1", "2612601001", "学生2", "123", "3", "", "", "13712345678" }); dataList.add(new String[] { "1", "2612601001", "学生3", "123", "3", "", "", "13712345678" }); dataList.add(new String[] { "1", "2612601001", "学生4", "123", "3", "", "", "13712345678" }); } //end test case ExcelHelper excelHelper = new ExcelHelper(fileName, sheetName, dataList); excelHelper.start(); long threadId = excelHelper.getId(); excelHelperMap.put(threadId, excelHelper); return threadId; } }
前台index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type='text/javascript' src='dwr/interface/ExcelHelperDWR.js'></script> <script type='text/javascript' src='dwr/engine.js'></script> <script type='text/javascript' src='dwr/util.js'></script> <script type="text/javascript"> var generateProgress; function beginProcess() { ExcelHelperDWR.beginProcess("D://我的Excel.xlsx", "sheet1",invoke); } function invoke(threadId) { generateProgress=window.setInterval("ExcelHelperDWR.getRowIndex("+threadId+", invokeCB)", 500); } function invokeCB(data) { if (data==-1) { window.clearInterval(generateProgress); document.getElementById("data").innerHTML = "生成Excel ok!"; } else { document.getElementById("data").innerHTML = data; } } </script> </head> <body> <input type="button" onclick="beginProcess()" value="generateExcel" /> <div id="data"></div> </body> </html>
OK了,很简易~
发表评论
-
hibernate的Criteria Query(转)
2014-06-29 21:22 681当查询数据时,人们往往需要设置查询条件。在SQL或HQL语句 ... -
【转】hibernate 中 Criteria 的使用介绍
2014-06-29 21:21 929转自:http://www.blogjava.net/jjs ... -
【转】Hibernate中Criteria的完整用法
2014-06-29 21:20 686转自:http://www.cnblogs.com/maba ... -
Java读写Oracle中的BLOB和CLOB
2013-10-16 18:00 1963转:http://www.iteye.com/topic/6 ... -
Spring的事务管理入门:编程式事务管理(TransactionTemplate)
2013-10-15 16:20 979可有效应用于Oracle 临时表的insert和select ... -
jdbcTemplate 调用存储过程和回到函数
2013-10-15 09:09 3716转:http://blog.csdn.net/dancelo ... -
Spring3核心技术之JdbcTemplate
2013-10-15 09:03 1264转:http://zhou137520.iteye.com/ ... -
验证码在WebLogic下报错java.io.IOException: response already committed
2013-05-06 14:16 2524我的登录验证码代码,一个jsp,在Tomcat下没有问题,但 ... -
Struts2在eclipse的console中总是出现WARN OgnlValueStack:45 - Could not find property
2013-04-17 18:00 1674struts2 在发开时,控制台如输出大量警告信息,太烦人 ... -
【转】Eclipse自动关闭解决方法及eclipse.ini设置
2013-03-29 15:21 3777转自:http://liujun5563.blog.163. ... -
[转]批量将Java源代码文件的编码从GBK转为UTF-8
2012-11-12 13:43 1464转自:http://my.oschina.net/binny/ ... -
对代理模式与Java动态代理类的理解
2012-09-25 01:51 01. 代理模式 代理模式的作用是:为其他对象提供一种 ... -
【转】 java中yield(),sleep()以及wait()的区别
2012-09-13 22:49 808从操作系统的角度讲,os会维护一个ready queue(就绪 ... -
java 继承类 变量、静态变量、构造函数执行顺序
2012-09-10 16:07 1005包含普通变量、静态变量、构造函数、继承类的执行顺序为: 1、父 ... -
京东2012春笔试编程题
2012-09-10 12:58 01、求给定数组中最大的K个数function array[] ... -
Java实现Stack、Queue、BinaryTree
2012-09-11 10:28 14341、用数组实现Stack: public class MySt ... -
Java中a++和++a的分析
2012-09-18 08:34 2829本人从编译后的代码来看a++和++a的区别: 先看代码1: ... -
华为2012校园上机编程题
2012-09-09 16:04 0/** * 1. 手机号码合法 ... -
2011年9月7日,华为上机题Java实现
2012-09-08 15:58 0第二题: /** * 输入字符串长度len,字符串str, ... -
Java对于Cookie的操作详解
2012-09-18 08:34 7881.设置Cookie Cookie cookie = n ...
相关推荐
1.java使用poi生成excel插入图表曲线 2.demo包含完成jar包 3.主要用途是过滤数据自动生成曲线图
POI生成Excel POI读取Excel java操作Excel Servlet生成Excel web项目,包含含读取Excel与生成Excel方法
poi excel poi excel poi excel poi excel poi excel poi excel poi excel poi excel
Java POI 生成Excel时显示货币格式
poi jxl 生成EXCEL 报表 POI 用的JAR poi-3.6-20091214.jar jxl 用到的jar jxl-2.6.jar
apache软件基金 poi组件 轻松实现,生成excel报表
使用poi生成Excel所需要的jar包,poi-3.9.jar
poi导入导出excel生成报表
平时工作中用到的一些技术点,拿出来和大家共享一下。 有些功能比较粗糙,如果大家有更加完善的示例或建议,欢迎交流。 1、jpg图片缩略图:ImageUtil ...2、poi创建excel:CDSHdlReport 3、计算表达式求值:Cal
Java POI根据模板生成Excel文件并写入磁盘,资源文件仅为实现的简单测试Demo,并没有进行代码优化,可以直接导入运行,资源文件仅供参考。
poi-3.0.2 生成excel表工具,java生成excel表格时使用
Java用POI实现根据Excel表格模板生成新的Excel并实现数据输出...
POI操作Excel生成水印,该水印其实就是一个图片,该代码是将文字生成图片,再将图片变成水印的。
本篇文章主要介绍了java后台利用Apache poi 生成excel文档提供前台下载示例,非常具有实用价值,需要的朋友可以参考下
Demo1 把数据写到excel表中, Demo2 在Demo1生成的excel中添加新的数据 Demo3 和Demo1一样生成一个excel表格 剩下的那个是从数据库取数据放到excel表格
java代码调用poi架包, 把数据生成excel文件, 导出到文件
SpringMVC POI Excel 生成导出
java poi 根据excel模板生成excel文件,利用poijar包根据已有excel模板,生成基于模板的新文件,jar包也在压缩包内,导入即可使用。
使用poi在excel中生成各种常见的图像,比如饼状图(普通饼状图、三D图,环状体、折线图、柱状图、等~~)
poi动态生成excel中下拉菜单,动态数据源,支持2003版本和2007版本