求教 : 以下代码如何优化

package com.itf.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

/**
 * @ClassName:  ExcelUtils   
 * @Description: 导出Excel工具类   
 * @date:   2019年4月15日  
 * @version : V1.0
 *
 * Modification History:
 * Date            Author        Version     Description
 * --------------------------------------------------------
 */
public class ExcelUtils {
    
    /**
     * @Title: exportSbhz   
     * @Description: 导出申报汇总
     * @param: @param list          申报汇总查询list
     * @param: @param version        版本
     * @param: @param sheetName        Excel名称
     * @return: void      
     * @throws
     * @date : 2019年4月15日   
     *
     * Modification History:
     * Date            Author        Version     Description
     * --------------------------------------------------------
     */
    public static void exportSbhz(List<Map<String, Object>> list,Integer version, String sheetName, HttpServletResponse response) {
  
        Map<String, Object> map = new HashMap<String, Object>();
        //头部信息
        List<String> headValList = new ArrayList<String>();
        //头部信息明确赋值
        headValList.addAll(Arrays.asList(new String[]{"123","123"}));
        List<String> headInfoValList = new ArrayList<String>();
        //头部信息辅助信息明确赋值
        headInfoValList.addAll(Arrays.asList(new String[]{"456","456"}));
        
        List<String> demoList = null; // 储存器
        //存储明细
        List<List<String>> realContentList = new ArrayList<List<String>>();
        realContentList.add(headInfoValList);
        if (list != null && list.size()>0) {
            for (Map<String, Object> i : list) {
                demoList = new ArrayList<String>(); 
            
                demoList.add(i.containsKey("xxx") ?i.get("xxx") != null ? i.get("xxx").toString() : "" : "");
             ........

                realContentList.add(demoList);
            } 
        }
        
        map.put("headValList", headValList);
        map.put("realContentList", realContentList);
        map.put("sheetName", sheetName);
        if(version != null && version == 1 ) map.put("excelVersion", "V2007");
        exportExcel(map,  "sbhz", response); // 调用生成Excel方法
    }
    
    /**
     * @Title: exportSbmx   
     * @Description: 导出申报明细
     * @param: @param list            申报明细集合
     * @param: @param version        版本 
     * @param: @param sheetName        Excel名称     
     * @return: void      
     * @throws
     * @date : 2019年4月15日   
     *
     * Modification History:
     * Date            Author        Version     Description
     * -------------------------------------------------------
     */
    public static void exportSbmx(List<Map<String, Object>> list, Integer version, String sheetName, HttpServletResponse response) {
        
        Map<String, Object> map = new HashMap<String, Object>();
        //头部信息
        List<String> headValList = new ArrayList<String>();
        //头部信息明确赋值
        headValList.addAll(Arrays.asList(new String[]{"789","789"}));
        List<String> headInfoValList = new ArrayList<String>();
        //头部信息明确赋值
        headInfoValList.addAll(Arrays.asList(new String[]{"147","147"}));
        
        List<String> demoList = null; // 储存器
        //存储明细
        List<List<String>> realContentList = new ArrayList<List<String>>();
        realContentList.add(headInfoValList);
        if (list != null && list.size()>0) {
            for (Map<String, Object> i : list) {
                demoList = new ArrayList<String>(); 
                
                demoList.add(i.containsKey("xxx") ? i.get("xxx") != null ? i.get("xxx").toString() : "" : "");
               .........

                realContentList.add(demoList);
            } 
        }
        
        map.put("headValList", headValList);
        map.put("realContentList", realContentList);
        map.put("sheetName", sheetName);
        if(version != null && version == 1 ) map.put("excelVersion", "V2007");
        exportExcel(map,  "sbmx", response); // 调用生成Excel方法
    }
    
    /**
     * @Title: exportGshz   
     * @Description: 导出个税汇总
     * @param: @param list        个税汇总集合
     * @param: @param version     版本     
     * @return: void      
     * @throws 
     * @date : 2019年4月15日   
     *
     * Modification History:
     * Date            Author        Version     Description
     * -------------------------------------------------------- 
     */
    public static void exportGshz(List<Map<String, Object>> list, Integer version, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();
        //头部信息
        List<String> headValList = new ArrayList<String>();
        //头部信息明确赋值
        headValList.addAll(Arrays.asList(new String[]{"132","321"}));
        List<String> demoList = null; // 储存器
        //存储明细
        List<List<String>> realContentList = new ArrayList<List<String>>();
        if (list != null && list.size()>0) {
            
            for (Map<String, Object> i : list) {
                 
                demoList = new ArrayList<String>(); 
                demoList.add(i.containsKey("xxx") ? i.get("xxx") != null ? i.get("xxx").toString() : "" : "");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值