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
--pom.xml 디펜던시 추가--
<!-- 액셀 jxls-->
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls</artifactId>
            <version>2.4.3</version>
        </dependency>
        
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-poi</artifactId>
            <version>1.0.14</version>
        </dependency>
        
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-jexcel</artifactId>
            <version>1.0.6</version>
        </dependency>
        
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-reader</artifactId>
            <version>2.0.3</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.17</version>
        </dependency>
 
--자바소스--
List<Map<String, Object>> list=서비스.겟리스트(search);
        String tempPath = request.getSession().getServletContext().getRealPath("/resources/excel/template");
        try(InputStream is = new BufferedInputStream(new FileInputStream(tempPath+"/템플릿.xlsx"))) {
            response.setHeader("Content-Disposition""attachment; filename=\"" + "다운받을파일명" + ".xlsx\"");            
            try (OutputStream os = response.getOutputStream()) {
                Context context = new Context();
                context.putVar("list", list);
                JxlsHelper.getInstance().processTemplate(is, os, context);
            }
        }
    }
 
--엑셀--
제목부분 메모
user: 
jx:area(lastCell="Q5")
첫번째셀 메모
user: 
jx:each(items="list" var="data" lastCell="Q5")
셀에들어가는내용
${data.key}
 
cs



2. 메모x forEach 사용안해도됨 workbook사용 XLSTransformer사용

엑셀 ${list.A}


시트네임설정

Context context = PoiTransformer.createInitialContext();
Workbook workbook = WorkbookFactory.create(templateInputStream);
workbook.setSheetName(0, "newName");//Changing name of the first sheet
PoiTransformer transformer = PoiTransformer.createTransformer(workbook);
transformer.setOutputStream(resultOutputstream);
JxlsHelper.getInstance().processTemplate(context, transformer);


'DEV > Spring&Java' 카테고리의 다른 글

Spring 인터셉터 Intercepter  (0) 2018.10.05
SHA256 암호화 키  (0) 2018.10.05
Javascript에서 ajax 많은데이터 넘길때  (0) 2018.10.05
Spring ajax통신  (0) 2018.10.05
Spring Mysql DB연동  (0) 2018.10.05