导出数据到Excel


HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("缴费日期");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("缴费号");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("金额");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("手续费");
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("缴费类型");
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("卡号后4位");
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("手机号");
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("流水号");
jnlsList = this.getBill2Service().getJnlsListByCriteria(
detachedCriteria);
Iterator itr = jnlsList.iterator();

WtPepJnls wtj;
short rowNum = 1;
String temp = "";
while (itr.hasNext()) {
wtj = (WtPepJnls) itr.next();
row = sheet.createRow(rowNum);
cell = row.createCell((short) 0);
temp = wtj.getPepdate();
temp = temp.substring(0, 4) + "-"
+ temp.substring(4, 6) + "-"
+ temp.substring(6, 8);
cell.setCellValue(temp);
cell = row.createCell((short) 1);
cell.setCellValue(wtj.getIntcdno());
cell = row.createCell((short) 2);
temp = "¥" + Util.FormatSum(wtj.getTranamt());
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(temp);
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("¥0.00");
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
temp = wtj.getTrancde();
if (temp.equals("M22")) {
cell.setCellValue("水费");
} else if (temp.equals("M24")) {
cell.setCellValue("电费");
} else if (temp.equals("M26")) {
cell.setCellValue("燃气费");
} else if (temp.equals("M2H")) {
cell.setCellValue("交通罚没费");
}
cell = row.createCell((short) 5);
temp = wtj.getOutcdno();
cell.setCellValue(temp.substring(12, 16));
cell = row.createCell((short) 6);
cell.setCellValue(wtj.getTermid());
cell = row.createCell((short) 7);
cell.setCellValue(wtj.getId().getTrace());

rowNum++;
}
response.setContentType("octets/stream");
response.addHeader("Content-Disposition",
"attachment;filename=all.xls");

OutputStream fileOut = response.getOutputStream();
wb.write(fileOut);
fileOut.close();
return null;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值