Java tutorial
/* * M2M ServiceFOTA ONM version 1.0 * * Copyright 2014 kt corp. All rights reserved. * * This is a proprietary software of kt corp, and you may not use this file except in * compliance with license agreement with kt corp. Any redistribution or use of this * software, with or without modification shall be strictly prohibited without prior written * approval of kt corp, and the copyright notice above does not evidence any actual or * intended publication of such software. */ package com.fota.fotastatMgt.controller; 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 com.fota.comm.util.DateTimeUtil; import com.fota.fotastatMgt.vo.FotastatSearchVO; public class FotastatExcelDown extends AbstractExcelView { @Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { String date = DateTimeUtil.getCurrentDate(); String formNm = "FOTA"; String fileName = date + "_" + formNm; String sheetName = "sheet1"; response.setContentType("application/vnd.ms-excel;charset=UTF-8"); response.setHeader("Content-disposition", "attachent; filename=" + new String((fileName).getBytes("KSC5601"), "8859_1") + ".xls"); @SuppressWarnings("unchecked") List<FotastatSearchVO> resultData = (List<FotastatSearchVO>) model.get("resultData"); HSSFSheet sheet = workbook.createSheet(sheetName); // ? HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("?"); header.createCell(1).setCellValue("FOTA Type"); header.createCell(2).setCellValue(""); header.createCell(3).setCellValue(""); header.createCell(4).setCellValue("?"); header.createCell(5).setCellValue("??"); header.createCell(6).setCellValue(""); header.createCell(7).setCellValue("?"); header.createCell(8).setCellValue("?"); header.createCell(9).setCellValue(""); //(ctn) header.createCell(10).setCellValue(""); header.createCell(11).setCellValue(""); header.createCell(12).setCellValue("?"); header.createCell(13).setCellValue("???"); header.createCell(14).setCellValue("PUSH"); int index = 0; if (resultData != null && resultData.size() > 0) { for (int i = 0; i < resultData.size(); i++) { FotastatSearchVO fvo = resultData.get(i); HSSFRow row = sheet.createRow(++index); row.createCell(0).setCellValue(fvo.getProcessStatCd()); row.createCell(1).setCellValue(fvo.getFotaType()); row.createCell(2).setCellValue(fvo.getBizNm()); row.createCell(3).setCellValue(fvo.getSvcNm()); row.createCell(4).setCellValue(fvo.getDevMakerNm()); row.createCell(5).setCellValue(fvo.getDevModelNm()); row.createCell(6).setCellValue(fvo.getModemMakerNm()); row.createCell(7).setCellValue(fvo.getModemModelNm()); row.createCell(8).setCellValue(fvo.getClientNm()); row.createCell(9).setCellValue(fvo.getDealerNm()); //(ctn) row.createCell(10).setCellValue(fvo.getDevFirmwareMakerVer()); row.createCell(11).setCellValue(fvo.getUpdFirmwareMakerVer()); row.createCell(12).setCellValue(fvo.getCretDt()); row.createCell(13).setCellValue(fvo.getDevNonAccPeriod()); row.createCell(14).setCellValue(fvo.getPushRsvYn()); } } workbook.write(response.getOutputStream()); response.getOutputStream().close(); } }