数据导出到EXCEL

1.             HSSFWorkbook wb = new HSSFWorkbook();  
2.             HSSFSheet sheet = wb.createSheet("new sheet");  
3.                    HSSFRow row = sheet.createRow((short) 0);  
4.                    HSSFCell cell = row.createCell((short) 0);  
5.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
6.                    cell.setCellValue("缴费日期");  
7.                    cell = row.createCell((short) 1);  
8.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
9.                    cell.setCellValue("缴费号");  
10.                    cell = row.createCell((short) 2);  
11.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
12.                    cell.setCellValue("金额");  
13.                    cell = row.createCell((short) 3);  
14.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
15.                    cell.setCellValue("手续费");  
16.                    cell = row.createCell((short) 4);  
17.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
18.                    cell.setCellValue("缴费类型");  
19.                    cell = row.createCell((short) 5);  
20.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
21.                    cell.setCellValue("卡号后4位");  
22.                    cell = row.createCell((short) 6);  
23.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
24.                    cell.setCellValue("手机号");  
25.                    cell = row.createCell((short) 7);  
26.                    cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
27.                    cell.setCellValue("流水号");  
28.jnlsList = this.getBill2Service().getJnlsListByCriteria(  
29.                            detachedCriteria);  
30.                    Iterator itr = jnlsList.iterator();  
31. 
32.                    WtPepJnls wtj;  
33.                    short rowNum = 1;  
34.                    String temp = "";  
35.                    while (itr.hasNext()) {  
36.                        wtj = (WtPepJnls) itr.next();  
37.                        row = sheet.createRow(rowNum);  
38.                        cell = row.createCell((short) 0);  
39.                        temp = wtj.getPepdate();  
40.                        temp = temp.substring(0, 4) + "-" 
41.                                + temp.substring(4, 6) + "-" 
42.                                + temp.substring(6, ;  
43.                        cell.setCellValue(temp);  
44.                        cell = row.createCell((short) 1);  
45.                        cell.setCellValue(wtj.getIntcdno());  
46.                        cell = row.createCell((short) 2);  
47.                        temp = "¥" + Util.FormatSum(wtj.getTranamt());  
48.                     cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
49.                        cell.setCellValue(temp);  
50.                        cell = row.createCell((short) 3);  
51.                     cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
52.                        cell.setCellValue("¥0.00");  
53.                        cell = row.createCell((short) 4);  
54.                     cell.setEncoding(HSSFCell.ENCODING_UTF_16);  
55.                        temp = wtj.getTrancde();  
56.                        if (temp.equals("M22")) {  
57.                            cell.setCellValue("水费");  
58.                        } else if (temp.equals("M24")) {  
59.                            cell.setCellValue("电费");  
60.                        } else if (temp.equals("M26")) {  
61.                            cell.setCellValue("燃气费");  
62.                        } else if (temp.equals("M2H")) {  
63.                            cell.setCellValue("交通罚没费");  
64.                        }  
65.                        cell = row.createCell((short) 5);  
66.                        temp = wtj.getOutcdno();  
67.                        cell.setCellValue(temp.substring(12, 16));  
68.                        cell = row.createCell((short) 6);  
69.                        cell.setCellValue(wtj.getTermid());  
70.                        cell = row.createCell((short) 7);  
71.                        cell.setCellValue(wtj.getId().getTrace());  
72. 
73.                        rowNum++;  
74.                    }  
75.                response.setContentType("octets/stream");  
76.                 response.addHeader("Content-Disposition",  
77.                                "attachment;filename=all.xls");  
78. 
79.               OutputStream fileOut = response.getOutputStream();  
80.                        wb.write(fileOut);  
81.                        fileOut.close();  
82.        return null;

猜你喜欢

转载自niuniul520-vip-qq-com.iteye.com/blog/1033764