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.qualityMgt.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.qualityMgt.vo.QulSearchVO; public class QualityInfoExcelDown 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<QulSearchVO> resultData = (List<QulSearchVO>) model.get("resultData"); HSSFSheet sheet = workbook.createSheet(sheetName); // ? HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue(""); header.createCell(1).setCellValue(""); //(ctn) header.createCell(2).setCellValue("?"); header.createCell(3).setCellValue("??"); header.createCell(4).setCellValue(""); header.createCell(5).setCellValue("?"); header.createCell(6).setCellValue("?"); header.createCell(7).setCellValue("ErrorDesc"); header.createCell(8).setCellValue(""); header.createCell(9).setCellValue("RAT"); header.createCell(10).setCellValue("RSSI"); header.createCell(11).setCellValue("()"); header.createCell(12).setCellValue("???"); header.createCell(13).setCellValue("??"); int index = 0; for (int i = 0; i < resultData.size(); i++) { QulSearchVO fvo = resultData.get(i); HSSFRow row = sheet.createRow(++index); row.createCell(0).setCellValue(fvo.getBizNm()); row.createCell(1).setCellValue(fvo.getSvcNm()); //(ctn) row.createCell(2).setCellValue(fvo.getDevMakerNm()); row.createCell(3).setCellValue(fvo.getDevModelNm()); row.createCell(4).setCellValue(fvo.getModemMakerNm()); row.createCell(5).setCellValue(fvo.getModemModelNm()); row.createCell(6).setCellValue(fvo.getDevQulInfo()); row.createCell(7).setCellValue(fvo.getErrorDesc()); row.createCell(8).setCellValue("(?)"); row.createCell(9).setCellValue(fvo.getRat()); row.createCell(10).setCellValue(fvo.getRssi()); row.createCell(11).setCellValue(fvo.getQulAccCycle()); row.createCell(12).setCellValue(fvo.getDevNonAccPeriod()); row.createCell(13).setCellValue(fvo.getLastAccDt()); } workbook.write(response.getOutputStream()); response.getOutputStream().close(); } }