Spring

[JXLS] JXLS EXCEL Templates์— ๊ทธ๋ฃน์„ ์—ฌ๋Ÿฌ ๊ฐœ ์‚ฌ์šฉ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ์‹œ ๋ฐœ์ƒํ–ˆ๋˜ ์ด์Šˆ

natrue 2021. 8. 4. 17:24
728x90
 

[JAVA] JXLS ์—‘์…€ ๋‹ค์šด๋กœ๋“œ

JXLS = JXLS์€ ํ…œํ”Œ๋ฆฟ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ตœ์ข… ์—‘์…€ํŒŒ์ผ์„ ์ƒ์„ฑ ๋ฐ์ดํ„ฐ (java ๊ฐ์ฒด) + ์—‘์…€ ํ…œํ”Œ๋ฆฟ = ์—‘์…€๊ฒฐ๊ณผ ์ถœ๋ ฅ ์—‘์…€์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์—‘์…€์˜ ์„œ์‹, ์ฐจํŠธ, ์ˆ˜์‹๋“ฑ์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค. pom.xml org.apache.

truecode-95.tistory.com

Controller

JXLS EXCEL Templates์— ๊ทธ๋ฃน์„ ์—ฌ๋Ÿฌ ๊ฐœ ์‚ฌ์šฉํ•˜๋ฉด [BK] cell ์ดํ›„ ๊ทธ๋ฃน์œผ๋กœ ๋ฌถ์€ ๊ฐ’๋“ค์€ ๋‚˜์˜ค์ง€ ์•Š๋Š”๋‹ค.

Map<String,Object> m0 = new HashMap<String,Object>();
m0.put("list", list); m0.put("title","์ œ๋ชฉ1"); 

Map<String,Object> m1 = new HashMap<String,Object>(); 
m1.put("list", list1); m1.put("title","์ œ๋ชฉ2"); 

List listAll = new ArrayList(); 
listAll.add(m1); 
listAll.add(m2); 

Context context = new Context(); 
context.putVar("listAll", listAll); 

HashMap<String, Object> doc = new HashMap<String, Object>(); 
doc.put("templateName","ํ…œํ”Œ๋ฆฟ์ด๋ฆ„"); 
doc.put("sheetName","์‹œํŠธ์ด๋ฆ„"); 
doc.put("context",context); 

service.downExcel(doc, request, response);

Excel Templates

ํ•ด๊ฒฐํ•œ๋ฐฉ๋ฒ•์€ ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฐ๊ฐ ๋ฟŒ๋ฆฌ์ง€ ๋ง๊ณ ๋ฆฌ์ŠคํŠธ ํ•˜๋‚˜๋ฅผ each๋ฌธ์œผ๋กœ ๋Œ๋ฆฌ์ž.

๋งŒ๋“  ์ด: jx:area(lastCell="U6") jx:each(items="listAll" var="la" lastCell="U6" direction="RIGHT" groupBy="list")