com.fota.statMgt.controller.StatDevExcelDown.java Source code

Java tutorial

Introduction

Here is the source code for com.fota.statMgt.controller.StatDevExcelDown.java

Source

/*
 * 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.statMgt.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.statMgt.vo.StatDevSearchVO;

public class StatDevExcelDown 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<StatDevSearchVO> resultData = (List<StatDevSearchVO>) model.get("resultData");

        HSSFSheet sheet = workbook.createSheet(sheetName);

        //  ?
        HSSFRow header = sheet.createRow(0);
        header.createCell(0).setCellValue("FOTA TYPE");
        header.createCell(1).setCellValue("");
        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("??");

        int index = 0;
        for (int i = 0; i < resultData.size(); i++) {
            StatDevSearchVO fvo = resultData.get(i);
            HSSFRow row = sheet.createRow(++index);
            row.createCell(0).setCellValue(fvo.getFotaType());
            row.createCell(1).setCellValue(fvo.getBizNm());
            row.createCell(2).setCellValue(fvo.getSvcNm());
            row.createCell(3).setCellValue(fvo.getDevMakerNm());
            row.createCell(4).setCellValue(fvo.getDevModelNm());
            row.createCell(5).setCellValue(fvo.getDevCntDtFrom());
            row.createCell(6).setCellValue(fvo.getDevCntDtTo());
            row.createCell(7).setCellValue(fvo.getIncDevCnt());
            row.createCell(8).setCellValue(fvo.getSumDevCntNow());
        }

        workbook.write(response.getOutputStream());
        response.getOutputStream().close();
    }

}