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.fota3g.statisticsMgt.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.fota3g.statisticsMgt.vo.NewFotaReportInfoVo; public class NewFotaReportExcelDown 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; 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<NewFotaReportInfoVo> fotaReportExcelList = (List<NewFotaReportInfoVo>) model .get("fotalReportExcelList"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // FOTA HSSFSheet sheet1 = workbook.createSheet("FOTA_"); // ? HSSFRow title = sheet1.createRow(0); title.createCell(0).setCellValue("FOTA_"); HSSFRow header = sheet1.createRow(1); header.createCell(0).setCellValue("FOTA ID"); header.createCell(1).setCellValue("FOTA "); header.createCell(2).setCellValue("??"); header.createCell(3).setCellValue("?"); header.createCell(4).setCellValue(" "); header.createCell(5).setCellValue("FOTA "); header.createCell(6).setCellValue(""); header.createCell(7).setCellValue("FOTA ? "); header.createCell(8).setCellValue(" ?"); header.createCell(9).setCellValue("? ?"); header.createCell(10).setCellValue("? ??"); header.createCell(11).setCellValue("DM Timeout"); header.createCell(12).setCellValue(""); int index = 1; if (fotaReportExcelList != null && fotaReportExcelList.size() > 0) { for (int i = 0; i < fotaReportExcelList.size(); i++) { NewFotaReportInfoVo fvo = fotaReportExcelList.get(i); HSSFRow row = sheet1.createRow(++index); row.createCell(0).setCellValue(fvo.getRequestId()); row.createCell(1).setCellValue(fvo.getRequestName()); row.createCell(2).setCellValue(fvo.getWriteDate()); row.createCell(3).setCellValue(fvo.getStartDate()); row.createCell(4).setCellValue(fvo.getStartTime() + "~" + fvo.getEndTime()); row.createCell(5).setCellValue(fvo.getTotalCount()); row.createCell(6).setCellValue(fvo.getSuccessCount()); row.createCell(7).setCellValue(fvo.getTotalFailCount()); row.createCell(8).setCellValue(fvo.getCancelDevCount()); row.createCell(9).setCellValue(fvo.getNonRegistedDevCount()); row.createCell(10).setCellValue(fvo.getDevSessionCloseCount()); row.createCell(11).setCellValue(fvo.getDmTimeoutCount()); row.createCell(12).setCellValue(fvo.getSuccessRate()); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// workbook.write(response.getOutputStream()); response.getOutputStream().close(); } }