67,549
社区成员




HttpServletResponse response = ServletActionContext.getResponse();
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
String path = "E:/BDC/SrcModule/obis-web/src/excel/财务费用.xls";
String fileName = URLEncoder.encode("财务费用明细表.xls", "UTF-8");
File f = new File(path);
response.setHeader("Content-Disposition", "attachment; filename="
+ fileName);
response.setHeader("Content-Length", String.valueOf(f.length()));
in = new BufferedInputStream(new FileInputStream(f));
// 创建Excel工作薄
Workbook work = new HSSFWorkbook(in);
Sheet sheet = work.getSheet("财务费用");
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
if (i == 0 || i == 2 || i == 3) {
continue;
} else if (i == 1 || i == 4 || i == 5 || i == 6 || i == 7
|| i == 8) {
if (i == 1) {
Row row = sheet.getRow((short) i);
String gsmc = (String) httpSession.getAttribute("gsmc");
Cell gsmcCell = row.getCell((short) 2);
gsmcCell.setCellValue("编制单位:" + gsmc);
Cell yuefenCell = row.getCell((short) 6);
yuefenCell.setCellValue(nf + "年" + yuefen + "月");
} else {
Row row = sheet.getRow((short) i);
Cell cell1 = row.getCell((short) 1);
Cell cell4 = row.getCell((short) 6);
cell1.setCellValue(listcaiwufeiyongInfoBean.get(i - 4)
.getSybqlj());
cell4.setCellValue(listcaiwufeiyongInfoBean.get(i - 4)
.getTqlj());
}
} else {
continue;
}
}
out = new BufferedOutputStream(response.getOutputStream());
work.write(out);
} catch (Exception e) {
logger.error("下载模版异常:", e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.error("下载模版异常:", e);
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
logger.error("下载模版异常:", e);
}
}
}