导出excel的两种方式

一、直接导出

/**
     * 
     * 方法描述:导出网格选中的全部数据为excel格式文件
     *
     * @param request
     * @param response
     * @return null
     * 返回值描述:返回值为null
     */
    @RequestMapping(value = "/exportToExcelAction")
    @ResponseBody
    public String exportToExcelAction(HttpServletRequest request, HttpServletResponse response,GspathpointinfoBo bo,String ids) {
	PageRequest pageRequest = this.getPage(request);
	// 列属性名称
	String propertyName ="ATHPOINTID,INFORMANT,FILLDATE,UPSTREAM,DOWNSTREAM,";
	propertyName = propertyName.toLowerCase();
	List<String> propertyList = new ArrayList<String>();
	if (propertyName != null) {
	    propertyList = Arrays.asList(propertyName.split(","));
	}
	// 列属性描述
	String propertyDes = "径识别点eventid,填报人,填报日期,上行流量,下行流量,";
	List<String> propertyDesList = new ArrayList<String>();
	if (propertyName != null) {
	    propertyDesList = Arrays.asList(propertyDes.split(","));
	}
	//设置excel数据最大导出记录数
	pageRequest.setPageSize(999999999);
	List<Map<String, String>> list = this.gspathpointinfoService.exportToExcel(pageRequest, bo, ids);
	//format导出数据的格式,确保数据的导出的正确性
	List<Map<String, String>> map = new ArrayList<Map<String, String>>();
	for (Map<String, String> ms : list) {
	    Set<String> key = ms.keySet();
	    Map mss = new HashMap();
	    for (Iterator it = key.iterator(); it.hasNext();) {
		String s = (String) it.next();
		Object valueObject = ms.get(s);
		String valueString = "";
		//如果为日期
		if (valueObject instanceof Date) {
		    valueString = DateTimeUtil.getFormatDate((Date) valueObject, DateTimeUtil.DATE_FORMAT);
		}
		if (valueObject != null) {
		    valueString = String.valueOf(valueObject);
		}
		mss.put(s, valueString);
	    }
	    map.add(mss);
	}
	//调用导出工具类导出数据
	new ExportDataUtil().exportDateListToWebExcel("路径识别点报表.xls", map, propertyList, propertyDesList, request,
				response);
	return null;
    }

  二、模板导出

/**
     * 方法描述:获得Excel文件
     *
     * @param
     * @return
     * @throws IOException 
     */
    @RequestMapping(value = "/downExcelFile")
    @ResponseBody
    public Map<String,List<Map<String,Object>>> downExcelFile(HttpServletRequest request, HttpServletResponse response) throws IOException{
	setLoginUser(request, gspathpointinfoService);
    String frontdate = request.getParameter("frontdate");
    String lastdate = request.getParameter("lastdate");
    String url = this.getClass().getClassLoader().getResource("").getPath()+"/template/德安高速公路路径识别流量汇总表.xls";
    File fi=new File(url);  
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fi));  
    //读取excel模板  
    HSSFWorkbook wb = new HSSFWorkbook(fs);  
    //读取了模板内所有sheet内容  
    HSSFSheet sheet = wb.getSheetAt(0); 
    Date date = DateTimeUtil.getDateFromDateString(frontdate);
    Calendar calendar=Calendar.getInstance();
    calendar.setTime(date);
    String title=sheet.getRow(0).getCell(0).getStringCellValue();
    title=title.replaceAll("\\{year\\}", String.valueOf(calendar.get(Calendar.YEAR)));
    title=title.replaceAll("\\{month\\}", String.valueOf(calendar.get(Calendar.MONTH)+1));
    
	sheet.getRow(0).getCell(0).setCellValue(title);
   List<Map<String,Object>> list = this.gspathpointinfoService.downExcelFile(frontdate, lastdate);
    List<Map<String,Object>> huayanxi = map.get("huayanxi");
    for(int i=0;i<huayanxi.size();i++){
    	sheet.getRow(2+(int)((Double)huayanxi.get(i).get("day")).intValue()).getCell(1).setCellValue(((BigDecimal)huayanxi.get(i).get("ns1")).doubleValue());
    	sheet.getRow(2+(int)((Double)huayanxi.get(i).get("day")).intValue()).getCell(2).setCellValue(((BigDecimal)huayanxi.get(i).get("ns2")).doubleValue());
    	sheet.getRow(2+(int)((Double)huayanxi.get(i).get("day")).intValue()).getCell(3).setCellValue(((BigDecimal)huayanxi.get(i).get("sn1")).doubleValue());
    	sheet.getRow(2+(int)((Double)huayanxi.get(i).get("day")).intValue()).getCell(4).setCellValue(((BigDecimal)huayanxi.get(i).get("sn2")).doubleValue());
    	sheet.getRow(2+(int)((Double)huayanxi.get(i).get("day")).intValue()).getCell(5).setCellValue(getBigerOne(((BigDecimal)huayanxi.get(i).get("sn1")).doubleValue(),((BigDecimal)huayanxi.get(i).get("sn2")).doubleValue())+getBigerOne(((BigDecimal)huayanxi.get(i).get("ns1")).doubleValue(),((BigDecimal)huayanxi.get(i).get("ns2")).doubleValue()));
   }
    List<Map<String,Object>> meicheng = map.get("meicheng");
    for(int i=0;i<meicheng.size();i++){
    	sheet.getRow(2+(int)((Double)meicheng.get(i).get("day")).intValue()).getCell(6).setCellValue(((BigDecimal)meicheng.get(i).get("ns1")).doubleValue());
    	sheet.getRow(2+(int)((Double)meicheng.get(i).get("day")).intValue()).getCell(7).setCellValue(((BigDecimal)meicheng.get(i).get("ns2")).doubleValue());
    	sheet.getRow(2+(int)((Double)meicheng.get(i).get("day")).intValue()).getCell(8).setCellValue(((BigDecimal)meicheng.get(i).get("sn1")).doubleValue());
    	sheet.getRow(2+(int)((Double)meicheng.get(i).get("day")).intValue()).getCell(9).setCellValue(((BigDecimal)meicheng.get(i).get("sn2")).doubleValue());
    	sheet.getRow(2+(int)((Double)meicheng.get(i).get("day")).intValue()).getCell(10).setCellValue(getBigerOne(((BigDecimal)meicheng.get(i).get("sn1")).doubleValue(),((BigDecimal)meicheng.get(i).get("sn2")).doubleValue())+getBigerOne(((BigDecimal)meicheng.get(i).get("ns1")).doubleValue(),((BigDecimal)meicheng.get(i).get("ns2")).doubleValue()));
    }
    updateFormula(wb,sheet,34);

    
    //修改模板内容导出新模板  
    FileOutputStream out = new FileOutputStream("D:/路径识别点报表.xls");  
    wb.write(out);  
    out.close();
    new ExportDataUtil().downloadExcelFile("D:/路径识别点报表.xls", request, response);
    return null; 
    }
    
    //更新Excel中的公式
    private static void updateFormula(Workbook wb,Sheet s,int row){
        Row r=s.getRow(row);
        Cell c=null;
        FormulaEvaluator eval=null;
        if(wb instanceof HSSFWorkbook)
            eval=new HSSFFormulaEvaluator((HSSFWorkbook) wb);
        else if(wb instanceof XSSFWorkbook)
            eval=new XSSFFormulaEvaluator((XSSFWorkbook) wb);
        for(int i=r.getFirstCellNum();i<r.getLastCellNum();i++){
            c=r.getCell(i);
            if(c.getCellType()==Cell.CELL_TYPE_FORMULA)
                eval.evaluateFormulaCell(c);
        }
    }

  工具类

import java.util.List;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ExcelUtil
{
  public static HSSFWorkbook exportDataToExcel(List<Map<String, String>> dataList, List<String> propertyList, List<String> propertyDesList, String[] param)
  {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFCellStyle style = wb.createCellStyle();
    style.setAlignment((short)2);
    
    HSSFSheet sheet = wb.createSheet("sheet1");
    sheet.setSelected(false);
    
    HSSFRow rowheader = sheet.createRow(0);
    for (int i = 0; i < propertyDesList.size(); i++)
    {
      String propertyDes = (String)propertyDesList.get(i);
      HSSFCell cell = rowheader.createCell((short)i);
      cell.setCellValue(propertyDes);
      cell.setCellStyle(style);
    }
    for (int i = 0; i < dataList.size(); i++)
    {
      Map<String, String> dataMap = (Map)dataList.get(i);
      HSSFRow row = sheet.createRow((short)i + 1);
      for (int j = 0; j < propertyList.size(); j++)
      {
        String propertyName = (String)propertyList.get(j);
        HSSFCell cell = row.createCell((short)j);
        String value = (String)dataMap.get(propertyName);
        if ((value == null) || ("null".equals(value))) {
          value = "";
        }
        cell.setCellValue(String.valueOf(value));
      }
    }
    return wb;
  }
}

  

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExportDataUtil
{
  protected static final Logger log = LoggerFactory.getLogger(ExportDataUtil.class);
  
  public void exportDataListToExcel(String exportExcelFileName, List<Object> objList, List<String> propertyList, List<String> propertyDesList, HttpServletRequest request, HttpServletResponse response)
  {
    List<Map<String, String>> dataList = convertToMapList(objList, propertyList);
    exportDateListToWebExcel(exportExcelFileName, dataList, propertyList, propertyDesList, request, response);
  }
  
  public List<Map<String, String>> convertToMapList(List objList, List<String> propertyList)
  {
    List<Map<String, String>> dataList = new ArrayList();
    try
    {
      Map<String, String> propertyMap = null;
      for (int i = 0; i < objList.size(); i++)
      {
        propertyMap = new LinkedHashMap();
        Object obj = objList.get(i);
        for (int j = 0; j < propertyList.size(); j++)
        {
          String propertyName = (String)propertyList.get(j);
          String propertyValue = "";
          if (propertyName != null)
          {
            String getterMethod = "get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
            propertyValue = String.valueOf(obj.getClass().getDeclaredMethod(getterMethod, null).invoke(obj, null));
            propertyMap.put(propertyName, propertyValue);
          }
        }
        dataList.add(propertyMap);
      }
      return dataList;
    }
    catch (IllegalArgumentException e)
    {
      e.printStackTrace();
    }
    catch (SecurityException e)
    {
      e.printStackTrace();
    }
    catch (IllegalAccessException e)
    {
      e.printStackTrace();
    }
    catch (InvocationTargetException e)
    {
      e.printStackTrace();
    }
    catch (NoSuchMethodException e)
    {
      e.printStackTrace();
    }
    return null;
  }
  
  public void exportDateListToWebExcel(String exportExcelFileName, List<Map<String, String>> dataList, List<String> propertyList, List<String> propertyDesList, HttpServletRequest request, HttpServletResponse response)
  {
    String[] param = { "1", "", "sheet1" };
    if ((CollectionUtil.isEmpty(dataList)) || (!StringUtil.hasLength(exportExcelFileName)) || (propertyList == null)) {
      return;
    }
    HSSFWorkbook wb = ExcelUtil.exportDataToExcel(dataList, propertyList, propertyDesList, param);
    downloadExcelFile(wb, exportExcelFileName, request, response);
  }
  
  /* Error */
  public void downloadExcelFile(String excelFilePath, HttpServletRequest request, HttpServletResponse response)
  {
    // Byte code:
    //   0: iconst_0
    //   1: istore 4
    //   3: sipush 8096
    //   6: newarray <illegal type>
    //   8: astore 5
    //   10: aconst_null
    //   11: astore 6
    //   13: aconst_null
    //   14: astore 7
    //   16: aload_3
    //   17: ldc -62
    //   19: invokeinterface 196 2 0
    //   24: aload_0
    //   25: aload_1
    //   26: invokespecial 201	cn/jasgroup/jasframework/utils/ExportDataUtil:getFileName	(Ljava/lang/String;)Ljava/lang/String;
    //   29: astore 8
    //   31: aload_3
    //   32: ldc -51
    //   34: new 68	java/lang/StringBuilder
    //   37: dup
    //   38: ldc -49
    //   40: invokespecial 71	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   43: aload 8
    //   45: ldc -47
    //   47: invokestatic 211	java/net/URLEncoder:encode	(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    //   50: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   53: invokevirtual 89	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   56: invokeinterface 217 3 0
    //   61: new 221	java/io/FileInputStream
    //   64: dup
    //   65: new 223	java/io/File
    //   68: dup
    //   69: aload_1
    //   70: invokespecial 225	java/io/File:<init>	(Ljava/lang/String;)V
    //   73: invokespecial 226	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   76: astore 6
    //   78: aload_3
    //   79: invokeinterface 229 1 0
    //   84: astore 7
    //   86: goto +16 -> 102
    //   89: aload 7
    //   91: aload 5
    //   93: iconst_0
    //   94: iload 4
    //   96: invokevirtual 233	java/io/OutputStream:write	([BII)V
    //   99: iconst_0
    //   100: istore 4
    //   102: aload 6
    //   104: aload 5
    //   106: invokevirtual 239	java/io/InputStream:read	([B)I
    //   109: dup
    //   110: istore 4
    //   112: iconst_m1
    //   113: if_icmpne -24 -> 89
    //   116: aload 7
    //   118: invokevirtual 245	java/io/OutputStream:flush	()V
    //   121: goto +163 -> 284
    //   124: astore 8
    //   126: getstatic 16	cn/jasgroup/jasframework/utils/ExportDataUtil:log	Lorg/slf4j/Logger;
    //   129: ldc -8
    //   131: invokeinterface 250 2 0
    //   136: aload 6
    //   138: ifnull +8 -> 146
    //   141: aload 6
    //   143: invokevirtual 255	java/io/InputStream:close	()V
    //   146: aload 7
    //   148: ifnull +166 -> 314
    //   151: aload 7
    //   153: invokevirtual 258	java/io/OutputStream:close	()V
    //   156: goto +158 -> 314
    //   159: astore 10
    //   161: aload 10
    //   163: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   166: goto +148 -> 314
    //   169: astore 8
    //   171: aload 8
    //   173: invokevirtual 262	java/io/FileNotFoundException:printStackTrace	()V
    //   176: aload 6
    //   178: ifnull +8 -> 186
    //   181: aload 6
    //   183: invokevirtual 255	java/io/InputStream:close	()V
    //   186: aload 7
    //   188: ifnull +126 -> 314
    //   191: aload 7
    //   193: invokevirtual 258	java/io/OutputStream:close	()V
    //   196: goto +118 -> 314
    //   199: astore 10
    //   201: aload 10
    //   203: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   206: goto +108 -> 314
    //   209: astore 8
    //   211: aload 8
    //   213: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   216: aload 6
    //   218: ifnull +8 -> 226
    //   221: aload 6
    //   223: invokevirtual 255	java/io/InputStream:close	()V
    //   226: aload 7
    //   228: ifnull +86 -> 314
    //   231: aload 7
    //   233: invokevirtual 258	java/io/OutputStream:close	()V
    //   236: goto +78 -> 314
    //   239: astore 10
    //   241: aload 10
    //   243: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   246: goto +68 -> 314
    //   249: astore 9
    //   251: aload 6
    //   253: ifnull +8 -> 261
    //   256: aload 6
    //   258: invokevirtual 255	java/io/InputStream:close	()V
    //   261: aload 7
    //   263: ifnull +18 -> 281
    //   266: aload 7
    //   268: invokevirtual 258	java/io/OutputStream:close	()V
    //   271: goto +10 -> 281
    //   274: astore 10
    //   276: aload 10
    //   278: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   281: aload 9
    //   283: athrow
    //   284: aload 6
    //   286: ifnull +8 -> 294
    //   289: aload 6
    //   291: invokevirtual 255	java/io/InputStream:close	()V
    //   294: aload 7
    //   296: ifnull +18 -> 314
    //   299: aload 7
    //   301: invokevirtual 258	java/io/OutputStream:close	()V
    //   304: goto +10 -> 314
    //   307: astore 10
    //   309: aload 10
    //   311: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   314: return
    // Line number table:
    //   Java source line #165	-> byte code offset #0
    //   Java source line #166	-> byte code offset #3
    //   Java source line #167	-> byte code offset #10
    //   Java source line #168	-> byte code offset #13
    //   Java source line #171	-> byte code offset #16
    //   Java source line #173	-> byte code offset #24
    //   Java source line #174	-> byte code offset #31
    //   Java source line #176	-> byte code offset #61
    //   Java source line #177	-> byte code offset #78
    //   Java source line #178	-> byte code offset #86
    //   Java source line #179	-> byte code offset #89
    //   Java source line #180	-> byte code offset #99
    //   Java source line #178	-> byte code offset #102
    //   Java source line #182	-> byte code offset #116
    //   Java source line #184	-> byte code offset #121
    //   Java source line #185	-> byte code offset #126
    //   Java source line #192	-> byte code offset #136
    //   Java source line #193	-> byte code offset #141
    //   Java source line #194	-> byte code offset #146
    //   Java source line #195	-> byte code offset #151
    //   Java source line #196	-> byte code offset #156
    //   Java source line #197	-> byte code offset #161
    //   Java source line #186	-> byte code offset #169
    //   Java source line #187	-> byte code offset #171
    //   Java source line #192	-> byte code offset #176
    //   Java source line #193	-> byte code offset #181
    //   Java source line #194	-> byte code offset #186
    //   Java source line #195	-> byte code offset #191
    //   Java source line #196	-> byte code offset #196
    //   Java source line #197	-> byte code offset #201
    //   Java source line #188	-> byte code offset #209
    //   Java source line #189	-> byte code offset #211
    //   Java source line #192	-> byte code offset #216
    //   Java source line #193	-> byte code offset #221
    //   Java source line #194	-> byte code offset #226
    //   Java source line #195	-> byte code offset #231
    //   Java source line #196	-> byte code offset #236
    //   Java source line #197	-> byte code offset #241
    //   Java source line #190	-> byte code offset #249
    //   Java source line #192	-> byte code offset #251
    //   Java source line #193	-> byte code offset #256
    //   Java source line #194	-> byte code offset #261
    //   Java source line #195	-> byte code offset #266
    //   Java source line #196	-> byte code offset #271
    //   Java source line #197	-> byte code offset #276
    //   Java source line #203	-> byte code offset #281
    //   Java source line #192	-> byte code offset #284
    //   Java source line #193	-> byte code offset #289
    //   Java source line #194	-> byte code offset #294
    //   Java source line #195	-> byte code offset #299
    //   Java source line #196	-> byte code offset #304
    //   Java source line #197	-> byte code offset #309
    //   Java source line #204	-> byte code offset #314
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	315	0	this	ExportDataUtil
    //   0	315	1	excelFilePath	String
    //   0	315	2	request	HttpServletRequest
    //   0	315	3	response	HttpServletResponse
    //   1	110	4	i	int
    //   8	97	5	b	byte[]
    //   11	279	6	is	java.io.InputStream
    //   14	286	7	os	java.io.OutputStream
    //   29	15	8	filename	String
    //   124	3	8	e	java.net.SocketException
    //   169	3	8	e	java.io.FileNotFoundException
    //   209	3	8	e	java.io.IOException
    //   249	33	9	localObject	Object
    //   159	3	10	e	java.io.IOException
    //   199	3	10	e	java.io.IOException
    //   239	3	10	e	java.io.IOException
    //   274	3	10	e	java.io.IOException
    //   307	3	10	e	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   16	121	124	java/net/SocketException
    //   136	156	159	java/io/IOException
    //   16	121	169	java/io/FileNotFoundException
    //   176	196	199	java/io/IOException
    //   16	121	209	java/io/IOException
    //   216	236	239	java/io/IOException
    //   16	136	249	finally
    //   169	176	249	finally
    //   209	216	249	finally
    //   251	271	274	java/io/IOException
    //   284	304	307	java/io/IOException
  }
  
  /* Error */
  private void downloadExcelFile(HSSFWorkbook hssfWorkbook, String excelFileName, HttpServletRequest request, HttpServletResponse response)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 5
    //   3: aload 4
    //   5: ldc -62
    //   7: invokeinterface 196 2 0
    //   12: aload_0
    //   13: aload_2
    //   14: invokespecial 201	cn/jasgroup/jasframework/utils/ExportDataUtil:getFileName	(Ljava/lang/String;)Ljava/lang/String;
    //   17: astore 6
    //   19: aload 4
    //   21: ldc -51
    //   23: new 68	java/lang/StringBuilder
    //   26: dup
    //   27: ldc -49
    //   29: invokespecial 71	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   32: aload 6
    //   34: ldc -47
    //   36: invokestatic 211	java/net/URLEncoder:encode	(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    //   39: invokevirtual 82	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   42: invokevirtual 89	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   45: invokeinterface 217 3 0
    //   50: aload 4
    //   52: invokeinterface 229 1 0
    //   57: astore 5
    //   59: aload_1
    //   60: aload 5
    //   62: invokevirtual 283	org/apache/poi/hssf/usermodel/HSSFWorkbook:write	(Ljava/io/OutputStream;)V
    //   65: aload 5
    //   67: invokevirtual 245	java/io/OutputStream:flush	()V
    //   70: goto +123 -> 193
    //   73: astore 6
    //   75: getstatic 16	cn/jasgroup/jasframework/utils/ExportDataUtil:log	Lorg/slf4j/Logger;
    //   78: ldc -8
    //   80: invokeinterface 250 2 0
    //   85: aload 5
    //   87: ifnull +126 -> 213
    //   90: aload 5
    //   92: invokevirtual 258	java/io/OutputStream:close	()V
    //   95: goto +118 -> 213
    //   98: astore 8
    //   100: aload 8
    //   102: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   105: goto +108 -> 213
    //   108: astore 6
    //   110: aload 6
    //   112: invokevirtual 262	java/io/FileNotFoundException:printStackTrace	()V
    //   115: aload 5
    //   117: ifnull +96 -> 213
    //   120: aload 5
    //   122: invokevirtual 258	java/io/OutputStream:close	()V
    //   125: goto +88 -> 213
    //   128: astore 8
    //   130: aload 8
    //   132: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   135: goto +78 -> 213
    //   138: astore 6
    //   140: aload 6
    //   142: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   145: aload 5
    //   147: ifnull +66 -> 213
    //   150: aload 5
    //   152: invokevirtual 258	java/io/OutputStream:close	()V
    //   155: goto +58 -> 213
    //   158: astore 8
    //   160: aload 8
    //   162: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   165: goto +48 -> 213
    //   168: astore 7
    //   170: aload 5
    //   172: ifnull +18 -> 190
    //   175: aload 5
    //   177: invokevirtual 258	java/io/OutputStream:close	()V
    //   180: goto +10 -> 190
    //   183: astore 8
    //   185: aload 8
    //   187: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   190: aload 7
    //   192: athrow
    //   193: aload 5
    //   195: ifnull +18 -> 213
    //   198: aload 5
    //   200: invokevirtual 258	java/io/OutputStream:close	()V
    //   203: goto +10 -> 213
    //   206: astore 8
    //   208: aload 8
    //   210: invokevirtual 259	java/io/IOException:printStackTrace	()V
    //   213: return
    // Line number table:
    //   Java source line #207	-> byte code offset #0
    //   Java source line #210	-> byte code offset #3
    //   Java source line #212	-> byte code offset #12
    //   Java source line #213	-> byte code offset #19
    //   Java source line #214	-> byte code offset #32
    //   Java source line #213	-> byte code offset #45
    //   Java source line #216	-> byte code offset #50
    //   Java source line #217	-> byte code offset #59
    //   Java source line #218	-> byte code offset #65
    //   Java source line #220	-> byte code offset #70
    //   Java source line #221	-> byte code offset #75
    //   Java source line #228	-> byte code offset #85
    //   Java source line #229	-> byte code offset #90
    //   Java source line #230	-> byte code offset #95
    //   Java source line #231	-> byte code offset #100
    //   Java source line #222	-> byte code offset #108
    //   Java source line #223	-> byte code offset #110
    //   Java source line #228	-> byte code offset #115
    //   Java source line #229	-> byte code offset #120
    //   Java source line #230	-> byte code offset #125
    //   Java source line #231	-> byte code offset #130
    //   Java source line #224	-> byte code offset #138
    //   Java source line #225	-> byte code offset #140
    //   Java source line #228	-> byte code offset #145
    //   Java source line #229	-> byte code offset #150
    //   Java source line #230	-> byte code offset #155
    //   Java source line #231	-> byte code offset #160
    //   Java source line #226	-> byte code offset #168
    //   Java source line #228	-> byte code offset #170
    //   Java source line #229	-> byte code offset #175
    //   Java source line #230	-> byte code offset #180
    //   Java source line #231	-> byte code offset #185
    //   Java source line #233	-> byte code offset #190
    //   Java source line #228	-> byte code offset #193
    //   Java source line #229	-> byte code offset #198
    //   Java source line #230	-> byte code offset #203
    //   Java source line #231	-> byte code offset #208
    //   Java source line #234	-> byte code offset #213
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	214	0	this	ExportDataUtil
    //   0	214	1	hssfWorkbook	HSSFWorkbook
    //   0	214	2	excelFileName	String
    //   0	214	3	request	HttpServletRequest
    //   0	214	4	response	HttpServletResponse
    //   1	198	5	os	java.io.OutputStream
    //   17	16	6	filename	String
    //   73	3	6	e	java.net.SocketException
    //   108	3	6	e	java.io.FileNotFoundException
    //   138	3	6	e	java.io.IOException
    //   168	23	7	localObject	Object
    //   98	3	8	e	java.io.IOException
    //   128	3	8	e	java.io.IOException
    //   158	3	8	e	java.io.IOException
    //   183	3	8	e	java.io.IOException
    //   206	3	8	e	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   3	70	73	java/net/SocketException
    //   85	95	98	java/io/IOException
    //   3	70	108	java/io/FileNotFoundException
    //   115	125	128	java/io/IOException
    //   3	70	138	java/io/IOException
    //   145	155	158	java/io/IOException
    //   3	85	168	finally
    //   108	115	168	finally
    //   138	145	168	finally
    //   170	180	183	java/io/IOException
    //   193	203	206	java/io/IOException
  }
  
  private String getFileName(String filePath)
  {
    String filename = filePath;
    int index = -1;
    if (filename.lastIndexOf("/") != -1) {
      index = filename.lastIndexOf("/");
    } else if (filename.lastIndexOf("//") != -1) {
      index = filename.lastIndexOf("//");
    } else if (filename.lastIndexOf("\\") != -1) {
      index = filename.lastIndexOf("\\");
    }
    filename = filename.substring(index + 1, filename.length());
    return filename;
  }
  
  private boolean isENum(String input)
  {
    String regx = "^((-?\\d+.?\\d*)[Ee]{1}(-?\\d+))$";
    Pattern pattern = Pattern.compile(regx);
    return pattern.matcher(input).matches();
  }
}

  

posted @ 2018-01-12 09:41  摩西摩西点点  阅读(1135)  评论(1编辑  收藏  举报