java根据模板导出功能

/**
* 监管导出
*
* @throws Exception
*/
@RequestMapping(params = "daoChuJianGuan")
public void daoChuJianGuan(HttpServletResponse response, HttpServletRequest request) throws Exception {
List<JianGuanTj> JianGuanTjs =getDataJianGuan(request);
//设置导出类型
response.setContentType("application/ms-excel;");
//获取项目的根目录
String path = request.getSession().getServletContext().getRealPath("/");
//根据项目的根目录找到Workbook
Workbook os = WorkbookFactory.create(new File(path + "template" + File.separator + "excel" + File.separator + "出入境特殊物品单位信息监管统计.xlsx"));
//获取模板上的sheet,‘统计’为模板的 sheet名称
Sheet sheet = os.getSheet("统计");
int jigouseek = 0;
JianGuanTj top = null;//实体
for (int i = 0; i < JianGuanTjs.size(); i++) {
JianGuanTj jianGuanTj = JianGuanTjs.get(i);
Row row=sheet.createRow(sheet.getLastRowNum() + 1);
//简单的,不涉及到合并单元格的,注释部分忽略
// if (top == null) {
// jigouseek = row.getRowNum();
// }else{
// if (!(top.getJigou().trim().equals(jianGuanTj.getJigou().trim()))) {
// if (jigouseek != row.getRowNum() - 1) {
// sheet.addMergedRegion(new CellRangeAddress(jigouseek, row.getRowNum() - 1, 0, 0));
// }
// jigouseek = row.getRowNum();
// }
// }
TSDepart tsDepart = (TSDepart) systemService.getEntity(TSDepart.class, jianGuanTj.getJigou());
if(tsDepart!=null){
row.createCell(0).setCellValue(tsDepart.getDepartname());
}else{
row.createCell(0).setCellValue(jianGuanTj.getJigou());
}
row.createCell(1).setCellValue(jianGuanTj.getXiangmu());
row.createCell(2).setCellValue(jianGuanTj.getHeJiCorpJiaShu());
row.createCell(3).setCellValue(jianGuanTj.getHeJiCorpJgCiShu());
row.createCell(4).setCellValue(jianGuanTj.getHeJiNotCorpJiaShu());
row.createCell(5).setCellValue(jianGuanTj.getHeJiNotCorpJgCiShu());
row.createCell(6).setCellValue(jianGuanTj.getHxJgXiaoJiJiaShu());
row.createCell(7).setCellValue(jianGuanTj.getHxJgXiaoJiCiShu());
row.createCell(8).setCellValue(jianGuanTj.getHxJgNotJiaShu());
row.createCell(9).setCellValue(jianGuanTj.getHxJgNotCiShu());
row.createCell(10).setCellValue(jianGuanTj.getRiChJgXiaoJiJiaShu());
row.createCell(11).setCellValue(jianGuanTj.getRiChJgXiaoJiCiShu());
row.createCell(12).setCellValue(jianGuanTj.getRiChJgNotJiaShu());
row.createCell(13).setCellValue(jianGuanTj.getRiChJgNotCiShu());
top=jianGuanTj;
}
//设置头部信息
response.setHeader("Content-disposition", "attachment; filename=" + new String(("出入境特殊物品单位信息监管统计.xlsx").getBytes("GBK"), "ISO8859-1"));
os.write(response.getOutputStream());
//关闭流。此处应该用try catch finally ,防止出现异常导致流无法关闭,内存溢出,只是此处省略。使用时切忌使用
response.getOutputStream().close();
}[align=left][size=x-small][/size][/align]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值