j2ee报表导出 做法是不是后台生成一个excel文件,然后再提供给用户下载? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是将页面统计出的数据表格以excel格式保存到本地上啊 jasperreports 很强大,而且网上的例子也很多 /** * 导出Excel */ public boolean userExcel(String userName,Date startDate,Date endDate) throws Exception { List<ChargeInfo> list = chargeInfoDao.findChargeInfoByUserName(userName,startDate,endDate); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("chargeInfo"); HSSFRow rowTitle = sheet.createRow(0); HSSFCell cellTitle1=rowTitle.createCell((short)0); cellTitle1.setCellType(HSSFCell.CELL_TYPE_STRING); cellTitle1.setEncoding(HSSFCell.ENCODING_UTF_16); cellTitle1.setCellValue("日期"); HSSFCell cellTitle2=rowTitle.createCell((short)1); cellTitle2.setCellType(HSSFCell.CELL_TYPE_STRING); cellTitle2.setEncoding(HSSFCell.ENCODING_UTF_16); cellTitle2.setCellValue("收费业务类型"); HSSFCell cellTitle3=rowTitle.createCell((short)2); cellTitle3.setCellType(HSSFCell.CELL_TYPE_STRING); cellTitle3.setEncoding(HSSFCell.ENCODING_UTF_16); cellTitle3.setCellValue("单价"); HSSFCell cellTitle4=rowTitle.createCell((short)3); cellTitle4.setCellType(HSSFCell.CELL_TYPE_STRING); cellTitle4.setEncoding(HSSFCell.ENCODING_UTF_16); cellTitle4.setCellValue("数量"); HSSFCell cellTitle5=rowTitle.createCell((short)4); cellTitle5.setCellType(HSSFCell.CELL_TYPE_STRING); cellTitle5.setEncoding(HSSFCell.ENCODING_UTF_16); cellTitle5.setCellValue("部门名称"); HSSFCell cellTitle6=rowTitle.createCell((short)5); cellTitle6.setCellType(HSSFCell.CELL_TYPE_STRING); cellTitle6.setEncoding(HSSFCell.ENCODING_UTF_16); cellTitle6.setCellValue("发票号码"); for (int i = 0; i < list.size(); i++) { HSSFRow row = sheet.createRow(i+1); ChargeInfo chargeInfo = list.get(i); row.createCell((short) 0).setCellValue(chargeInfo.getInvoiceNumber()); //entity 属性字段 HSSFCell cell1 = row.createCell((short) 1); cell1.setCellType(HSSFCell.CELL_TYPE_STRING); cell1.setEncoding(HSSFCell.ENCODING_UTF_16); cell1.setCellValue(chargeInfo.getChargeOperationInfo().getOperationName()); //收费业务类型 HSSFCell cell2 = row.createCell((short) 2); cell2.setCellValue(chargeInfo.getChargePrice()); //单价 HSSFCell cell3 = row.createCell((short) 3); cell3.setCellValue(chargeInfo.getChargeQuantity()); //数量 HSSFCell cell4 = row.createCell((short) 4); cell4.setCellType(HSSFCell.CELL_TYPE_STRING); cell4.setEncoding(HSSFCell.ENCODING_UTF_16); cell4.setCellValue(chargeInfo.getDeptInfo().getDeptName()); //部门名称 HSSFCellStyle cellStyle=workbook.createCellStyle(); //建立新的cell样式 cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("yy-m-d h:mm")); //设置cell样式为定制的日期格式 HSSFCell cell5 = row.createCell((short) 5); cell5.setCellValue(chargeInfo.getChargeDate()); //日期 cell5.setCellStyle(cellStyle); } byte[] bytes = workbook.getBytes(); // workbook.ENCODING_COMPRESSED_UNICODE; workbook.setSheetName(0, "第一页",HSSFWorkbook.ENCODING_UTF_16); FileOutputStream file = new FileOutputStream("E:/ChargeInfo.xls"); workbook.write(file); file.flush(); //file.write(bytes, 0, bytes.length); file.close(); return true; } ecside 这个是列表的插件,可以支持导出excel 和pdf。 导出excel有很多种实现方式,主要看你的业务需求复杂程度怎么样?如果简单的话 就没必要用什么插件、直接点导出的时候重新进入action查询一次,然后返回到新的jsp页面 新的jsp页面设置 直接下载就行 用插件的话 有很多 比如说 poi jxl birt等 都不错! 一个账户只能一个人使用 spring aop 问题 java抓取新闻 关于spring+hibernate的问题,请求各位帮忙看看,谢谢 Ext实现文件下载 急救!URL流中文编码问题! 小妹是初学者,请帮帮小妹 高分相送! oracle中文版的时间/日期字段问题,请帮帮我 redis 并发操作引起的问题 一个关于JDBC事务方面的效率问题 ssh2项目,表单提交到业务层时JSP报空指针错,请问都有哪些原因造成的?
* 导出Excel
*/
public boolean userExcel(String userName,Date startDate,Date endDate) throws Exception {
List<ChargeInfo> list = chargeInfoDao.findChargeInfoByUserName(userName,startDate,endDate);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("chargeInfo");
HSSFRow rowTitle = sheet.createRow(0);
HSSFCell cellTitle1=rowTitle.createCell((short)0);
cellTitle1.setCellType(HSSFCell.CELL_TYPE_STRING);
cellTitle1.setEncoding(HSSFCell.ENCODING_UTF_16);
cellTitle1.setCellValue("日期");
HSSFCell cellTitle2=rowTitle.createCell((short)1);
cellTitle2.setCellType(HSSFCell.CELL_TYPE_STRING);
cellTitle2.setEncoding(HSSFCell.ENCODING_UTF_16);
cellTitle2.setCellValue("收费业务类型");
HSSFCell cellTitle3=rowTitle.createCell((short)2);
cellTitle3.setCellType(HSSFCell.CELL_TYPE_STRING);
cellTitle3.setEncoding(HSSFCell.ENCODING_UTF_16);
cellTitle3.setCellValue("单价");
HSSFCell cellTitle4=rowTitle.createCell((short)3);
cellTitle4.setCellType(HSSFCell.CELL_TYPE_STRING);
cellTitle4.setEncoding(HSSFCell.ENCODING_UTF_16);
cellTitle4.setCellValue("数量");
HSSFCell cellTitle5=rowTitle.createCell((short)4);
cellTitle5.setCellType(HSSFCell.CELL_TYPE_STRING);
cellTitle5.setEncoding(HSSFCell.ENCODING_UTF_16);
cellTitle5.setCellValue("部门名称");
HSSFCell cellTitle6=rowTitle.createCell((short)5);
cellTitle6.setCellType(HSSFCell.CELL_TYPE_STRING);
cellTitle6.setEncoding(HSSFCell.ENCODING_UTF_16);
cellTitle6.setCellValue("发票号码");
for (int i = 0; i < list.size(); i++) {
HSSFRow row = sheet.createRow(i+1); ChargeInfo chargeInfo = list.get(i);
row.createCell((short) 0).setCellValue(chargeInfo.getInvoiceNumber()); //entity 属性字段
HSSFCell cell1 = row.createCell((short) 1);
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);
cell1.setCellValue(chargeInfo.getChargeOperationInfo().getOperationName()); //收费业务类型 HSSFCell cell2 = row.createCell((short) 2);
cell2.setCellValue(chargeInfo.getChargePrice()); //单价
HSSFCell cell3 = row.createCell((short) 3);
cell3.setCellValue(chargeInfo.getChargeQuantity()); //数量
HSSFCell cell4 = row.createCell((short) 4);
cell4.setCellType(HSSFCell.CELL_TYPE_STRING);
cell4.setEncoding(HSSFCell.ENCODING_UTF_16);
cell4.setCellValue(chargeInfo.getDeptInfo().getDeptName()); //部门名称 HSSFCellStyle cellStyle=workbook.createCellStyle(); //建立新的cell样式
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("yy-m-d h:mm")); //设置cell样式为定制的日期格式
HSSFCell cell5 = row.createCell((short) 5);
cell5.setCellValue(chargeInfo.getChargeDate()); //日期
cell5.setCellStyle(cellStyle);
}
byte[] bytes = workbook.getBytes();
// workbook.ENCODING_COMPRESSED_UNICODE;
workbook.setSheetName(0, "第一页",HSSFWorkbook.ENCODING_UTF_16);
FileOutputStream file = new FileOutputStream("E:/ChargeInfo.xls");
workbook.write(file);
file.flush();
//file.write(bytes, 0, bytes.length);
file.close();
return true;
}
如果简单的话 就没必要用什么插件、直接点导出的时候重新进入action查询一次,
然后返回到新的jsp页面 新的jsp页面设置 直接下载就行