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.HashMap; 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.FirmwareVersionVo; public class PkgDownExcelDown extends AbstractExcelView { @Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { String date = DateTimeUtil.getCurrentDate(); String formNm = " "; 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<FirmwareVersionVo> columnList = (List<FirmwareVersionVo>) model.get("columnList"); @SuppressWarnings("unchecked") List resultList = (List) model.get("resultList"); HSSFSheet sheet = workbook.createSheet(sheetName); // ? HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("??"); for (int i = 0, j = 1; i < columnList.size(); i++, j++) { header.createCell(j).setCellValue(columnList.get(i).getVersion()); } header.createCell(columnList.size()).setCellValue(""); // ?? int index = 0; HashMap<String, String> tempResultItemMap = null; for (int i = 0; i < resultList.size(); i++) { HSSFRow row = sheet.createRow(++index); tempResultItemMap = (HashMap) resultList.get(i); row.createCell(0).setCellValue(tempResultItemMap.get("01_SUMDATE").toString()); for (int j = 0, k = 1; j < columnList.size(); j++, k++) { row.createCell(k).setCellValue(tempResultItemMap.get(columnList.get(j).getVersion()).toString()); } row.createCell(columnList.size()).setCellValue(tempResultItemMap.get("ROW_SUM").toString()); } // end of for(int i=0; i<resultList.size(); i++) workbook.write(response.getOutputStream()); response.getOutputStream().close(); } }