티스토리 뷰

JAVA

java 엑셀 다운로드

KIMSG 2017. 7. 21. 14:12

dispatcher-servlet.xml  에
1
<bean name="excelView" class="egovframework.utils.ExcelLoader"/>
cs


ExcelLoader.java 에


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package egovframework.utils;
 
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;
 
import egovframework.front.cal.vo.CalcVO;
import egovframework.sys.stt.vo.StatsVO;
 
public class ExcelLoader extends AbstractExcelView{
    @Override   
    protected void buildExcelDocument(Map<String,Object> ModelMap,HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception{
             HSSFSheet worksheet = null;
             HSSFRow row = null;
 
             worksheet = workbook.createSheet("sheet1");
             String fileName = "";
 
             if(ModelMap.get("excelKey").equals("calc")){
                 fileName = "calc";
                 List<CalcVO> list = (List<CalcVO>)ModelMap.get("excelList");
 
                 row = worksheet.createRow(0);
                 row.createCell(0).setCellValue("거래번호");
                 
                 for(int i=0;i<list.size();i++){
                     row = worksheet.createRow(i+1);
                     row.createCell(0).setCellValue(list.get(i).getOrdNo());
                     
                 }
 
             }else if(ModelMap.get("excelKey").equals("stats_cate")){
                 fileName = "stats_cate";
                 List<StatsVO> list = (List<StatsVO>)ModelMap.get("excelList");
 
                 row = worksheet.createRow(0);
                 row.createCell(0).setCellValue("월/일");
                 
                 for(int i=0;i<list.size();i++){
                     row = worksheet.createRow(i+1);
                     row.createCell(0).setCellValue(list.get(i).getOrdDt());
                    
                 }
             }else if(ModelMap.get("excelKey").equals("stats_user")){
                 fileName = "stats_user";
                 List<StatsVO> list = (List<StatsVO>)ModelMap.get("excelList");
 
                 row = worksheet.createRow(0);
                 row.createCell(1).setCellValue("1월");
                
 
                 for(int i=0;i<list.size();i++){
                     row = worksheet.createRow(i+1);
                     row.createCell(0).setCellValue(list.get(i).getUserNm());
                    
                 }
             }else if(ModelMap.get("excelKey").equals("stats_prod")){
                 fileName = "stats_prod";
                 List<StatsVO> list = (List<StatsVO>)ModelMap.get("excelList");
 
                 row = worksheet.createRow(0);
                 row.createCell(0).setCellValue("월/일");
                
                 for(int i=0;i<list.size();i++){
                     row = worksheet.createRow(i+1);
                     row.createCell(0).setCellValue(list.get(i).getOrdDt());
                     
                 }
             }
 
 
             response.setContentType("Application/Msexcel");
             response.setHeader("Content-Disposition""ATTachment; Filename="+fileName+"_"+DateUtil.getCurrentDate("yyyyMMdd")+".xls");
       }
}
 
cs


'JAVA' 카테고리의 다른 글

암호화하기 1 ( SHA256)  (0) 2017.07.21
파일 확장자 판별 하기  (0) 2017.07.21
디컴파일  (0) 2017.07.21
파일 업로드  (0) 2017.07.21
float형을 string으로  (0) 2017.07.21
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함