j2ee报表导出

kyousuke 2012-04-11 01:53:24
做法是不是后台生成一个excel文件,然后再提供给用户下载?
...全文
166 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
JerryZhou_ 2012-04-11
  • 打赏
  • 举报
回复
用插件的话 有很多 比如说 poi jxl birt等 都不错!
JerryZhou_ 2012-04-11
  • 打赏
  • 举报
回复
导出excel有很多种实现方式,主要看你的业务需求复杂程度怎么样?
如果简单的话 就没必要用什么插件、直接点导出的时候重新进入action查询一次,
然后返回到新的jsp页面 新的jsp页面设置 直接下载就行
cheneyfeng3 2012-04-11
  • 打赏
  • 举报
回复
ecside 这个是列表的插件,可以支持导出excel 和pdf。
佳峰 2012-04-11
  • 打赏
  • 举报
回复
这只是一个例子,具体的需要你去看咯
佳峰 2012-04-11
  • 打赏
  • 举报
回复
/**
* 导出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;
}
xuguiyi100 2012-04-11
  • 打赏
  • 举报
回复
jasperreports 很强大,而且网上的例子也很多
kyousuke 2012-04-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
你要做什么?
[/Quote]
就是将页面统计出的数据表格以excel格式保存到本地上啊
xdh112 2012-04-11
  • 打赏
  • 举报
回复
你要做什么?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧