org.jeecgframework.poi.excel.ExcelExportUtil Java Examples

The following examples show how to use org.jeecgframework.poi.excel.ExcelExportUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JeecgTemplateExcelView.java    From autopoi with Apache License 2.0 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	String codedFileName = "临时文件";
	Workbook workbook = ExcelExportUtil.exportExcel((TemplateExportParams) model.get(TemplateExcelConstants.PARAMS), (Class<?>) model.get(TemplateExcelConstants.CLASS), (List<?>) model.get(TemplateExcelConstants.LIST_DATA), (Map<String, Object>) model.get(TemplateExcelConstants.MAP_DATA));
	if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
		codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
	}
	if (workbook instanceof HSSFWorkbook) {
		codedFileName += HSSF;
	} else {
		codedFileName += XSSF;
	}
	if (isIE(request)) {
		codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
	} else {
		codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
	}
	response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
	ServletOutputStream out = response.getOutputStream();
	workbook.write(out);
	out.flush();
}
 
Example #2
Source File: JeecgMapExcelView.java    From autopoi with Apache License 2.0 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	String codedFileName = "临时文件";
	Workbook workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(MapExcelConstants.PARAMS), (List<ExcelExportEntity>) model.get(MapExcelConstants.ENTITY_LIST), (Collection<? extends Map<?, ?>>) model.get(MapExcelConstants.MAP_LIST));
	if (model.containsKey(MapExcelConstants.FILE_NAME)) {
		codedFileName = (String) model.get(MapExcelConstants.FILE_NAME);
	}
	if (workbook instanceof HSSFWorkbook) {
		codedFileName += HSSF;
	} else {
		codedFileName += XSSF;
	}
	if (isIE(request)) {
		codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
	} else {
		codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
	}
	response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
	ServletOutputStream out = response.getOutputStream();
	workbook.write(out);
	out.flush();
}
 
Example #3
Source File: JeecgTemplateExcelView.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	String codedFileName = "临时文件";
	Workbook workbook = ExcelExportUtil.exportExcel((TemplateExportParams) model.get(TemplateExcelConstants.PARAMS), (Class<?>) model.get(TemplateExcelConstants.CLASS), (List<?>) model.get(TemplateExcelConstants.LIST_DATA), (Map<String, Object>) model.get(TemplateExcelConstants.MAP_DATA));
	if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
		codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
	}
	if (workbook instanceof HSSFWorkbook) {
		codedFileName += HSSF;
	} else {
		codedFileName += XSSF;
	}
	if (isIE(request)) {
		codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
	} else {
		codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
	}
	response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
	ServletOutputStream out = response.getOutputStream();
	workbook.write(out);
	out.flush();
}
 
Example #4
Source File: JeecgMapExcelView.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	String codedFileName = "临时文件";
	Workbook workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(MapExcelConstants.PARAMS), (List<ExcelExportEntity>) model.get(MapExcelConstants.ENTITY_LIST), (Collection<? extends Map<?, ?>>) model.get(MapExcelConstants.MAP_LIST));
	if (model.containsKey(MapExcelConstants.FILE_NAME)) {
		codedFileName = (String) model.get(MapExcelConstants.FILE_NAME);
	}
	if (workbook instanceof HSSFWorkbook) {
		codedFileName += HSSF;
	} else {
		codedFileName += XSSF;
	}
	if (isIE(request)) {
		codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
	} else {
		codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
	}
	response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
	ServletOutputStream out = response.getOutputStream();
	workbook.write(out);
	out.flush();
}
 
Example #5
Source File: JeecgMapExcelView.java    From easypoi with Apache License 2.0 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
    String codedFileName = "临时文件";
    Workbook workbook = ExcelExportUtil.exportExcel(
        (ExportParams) model.get(MapExcelConstants.PARAMS),
        (List<ExcelExportEntity>) model.get(MapExcelConstants.ENTITY_LIST),
        (Collection<? extends Map<?, ?>>) model.get(MapExcelConstants.MAP_LIST));
    if (model.containsKey(MapExcelConstants.FILE_NAME)) {
        codedFileName = (String) model.get(MapExcelConstants.FILE_NAME);
    }
    if (workbook instanceof HSSFWorkbook) {
        codedFileName += HSSF;
    } else {
        codedFileName += XSSF;
    }
    if (isIE(request)) {
        codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
    } else {
        codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
    }
    response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
    ServletOutputStream out = response.getOutputStream();
    workbook.write(out);
    out.flush();
}
 
Example #6
Source File: JeecgSingleExcelView.java    From jeewx with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildExcelDocument(Map<String, Object> model,
                                  HSSFWorkbook hssfWorkbook, HttpServletRequest httpServletRequest,
                                  HttpServletResponse httpServletResponse) throws Exception {
    String codedFileName = "临时文件.xls";
    if (model.containsKey(POIConstants.FILE_NAME)) {
        codedFileName = (String) model.get(POIConstants.FILE_NAME)+".xls";
    }
    httpServletResponse.setHeader(
            "content-disposition",
            "attachment;filename=" + new String(codedFileName.getBytes(), "iso8859-1"));
    if (model.containsKey(POIConstants.MAP_LIST)) {
        List<Map<String, Object>> list = (List<Map<String, Object>>) model.get(POIConstants.MAP_LIST);
        for (Map<String, Object> map : list) {
            ExcelExportUtil.createSheetInUserModel2File(hssfWorkbook,
                    (ExcelTitle) map.get(POIConstants.EXCEL_TITLE),
                    (Class<?>) map.get(POIConstants.CLASS),
                    (Collection<?>) map.get(POIConstants.DATA_LIST));
        }
    } else {
        ExcelExportUtil.createSheetInUserModel2File(hssfWorkbook,
                (ExcelTitle) model.get(POIConstants.EXCEL_TITLE), (Class<?>) model.get(POIConstants.CLASS),
                (Collection<?>) model.get(POIConstants.DATA_LIST));
    }
}
 
Example #7
Source File: JeecgSingleExcelView.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	String codedFileName = "临时文件";
	Workbook workbook = null;
	if (model.containsKey(NormalExcelConstants.MAP_LIST)) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) model.get(NormalExcelConstants.MAP_LIST);
		if (list.size() == 0) {
			throw new RuntimeException("MAP_LIST IS NULL");
		}
		workbook = ExcelExportUtil.exportExcel((ExportParams) list.get(0).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(0).get(NormalExcelConstants.CLASS), (Collection<?>) list.get(0).get(NormalExcelConstants.DATA_LIST));
		for (int i = 1; i < list.size(); i++) {
			new ExcelExportServer().createSheet(workbook, (ExportParams) list.get(i).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(i).get(NormalExcelConstants.CLASS), (Collection<?>) list.get(i).get(NormalExcelConstants.DATA_LIST));
		}
	} else {
		workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(NormalExcelConstants.PARAMS), (Class<?>) model.get(NormalExcelConstants.CLASS), (Collection<?>) model.get(NormalExcelConstants.DATA_LIST));
	}
	if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
		codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
	}
	if (workbook instanceof HSSFWorkbook) {
		codedFileName += HSSF;
	} else {
		codedFileName += XSSF;
	}
	if (isIE(request)) {
		codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
	} else {
		codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
	}
	response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
	ServletOutputStream out = response.getOutputStream();
	workbook.write(out);
	out.flush();
}
 
Example #8
Source File: JeecgTemplateExcelView.java    From easypoi with Apache License 2.0 5 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
    String codedFileName = "临时文件";
    Workbook workbook = ExcelExportUtil.exportExcel(
        (TemplateExportParams) model.get(TemplateExcelConstants.PARAMS),
        (Class<?>) model.get(TemplateExcelConstants.CLASS),
        (List<?>) model.get(TemplateExcelConstants.LIST_DATA),
        (Map<String, Object>) model.get(TemplateExcelConstants.MAP_DATA));
    if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
        codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
    }
    if (workbook instanceof HSSFWorkbook) {
        codedFileName += HSSF;
    } else {
        codedFileName += XSSF;
    }
    if (isIE(request)) {
        codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
    } else {
        codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
    }
    response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
    ServletOutputStream out = response.getOutputStream();
    workbook.write(out);
    out.flush();
}
 
Example #9
Source File: JeecgEntityExcelView.java    From autopoi with Apache License 2.0 4 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	String codedFileName = "临时文件";
	Workbook workbook = null;
	//---update-end-----autor:scott------date:20191016-------for:导出字段支持自定义--------
	String[] exportFields = null;

	Object exportFieldStr =  model.get(NormalExcelConstants.EXPORT_FIELDS);
	if(exportFieldStr!=null && exportFieldStr!=""){
		exportFields = exportFieldStr.toString().split(",");
	}
       //---update-end-----autor:scott------date:20191016-------for:导出字段支持自定义--------
	if (model.containsKey(NormalExcelConstants.MAP_LIST)) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) model.get(NormalExcelConstants.MAP_LIST);
		if (list.size() == 0) {
			throw new RuntimeException("MAP_LIST IS NULL");
		}
		workbook = ExcelExportUtil.exportExcel((ExportParams) list.get(0).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(0).get(NormalExcelConstants.CLASS), (Collection<?>) list.get(0).get(NormalExcelConstants.DATA_LIST),exportFields);
		for (int i = 1; i < list.size(); i++) {
			new ExcelExportServer().createSheet(workbook, (ExportParams) list.get(i).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(i).get(NormalExcelConstants.CLASS), (Collection<?>) list.get(i).get(NormalExcelConstants.DATA_LIST),exportFields);
		}
	} else {
		workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(NormalExcelConstants.PARAMS), (Class<?>) model.get(NormalExcelConstants.CLASS), (Collection<?>) model.get(NormalExcelConstants.DATA_LIST),exportFields);
	}
	if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
		codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
	}
	if (workbook instanceof HSSFWorkbook) {
		codedFileName += HSSF;
	} else {
		codedFileName += XSSF;
	}
	if (isIE(request)) {
		codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
	} else {
		codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
	}
	response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
	ServletOutputStream out = response.getOutputStream();
	workbook.write(out);
	out.flush();
}
 
Example #10
Source File: JeecgSingleExcelView.java    From easypoi with Apache License 2.0 4 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
    String codedFileName = "临时文件";
    Workbook workbook = null;
    if (model.containsKey(NormalExcelConstants.MAP_LIST)) {
        List<Map<String, Object>> list = (List<Map<String, Object>>) model
            .get(NormalExcelConstants.MAP_LIST);
        if (list.size() == 0) {
            throw new RuntimeException("MAP_LIST IS NULL");
        }
        workbook = ExcelExportUtil.exportExcel(
            (ExportParams) list.get(0).get(NormalExcelConstants.PARAMS), (Class<?>) list.get(0)
                .get(NormalExcelConstants.CLASS),
            (Collection<?>) list.get(0).get(NormalExcelConstants.DATA_LIST));
        for (int i = 1; i < list.size(); i++) {
            new ExcelExportServer().createSheet(workbook,
                (ExportParams) list.get(i).get(NormalExcelConstants.PARAMS), (Class<?>) list
                    .get(i).get(NormalExcelConstants.CLASS),
                (Collection<?>) list.get(i).get(NormalExcelConstants.DATA_LIST));
        }
    } else {
        workbook = ExcelExportUtil.exportExcel(
            (ExportParams) model.get(NormalExcelConstants.PARAMS),
            (Class<?>) model.get(NormalExcelConstants.CLASS),
            (Collection<?>) model.get(NormalExcelConstants.DATA_LIST));
    }
    if (model.containsKey(NormalExcelConstants.FILE_NAME)) {
        codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME);
    }
    if (workbook instanceof HSSFWorkbook) {
        codedFileName += HSSF;
    } else {
        codedFileName += XSSF;
    }
    if (isIE(request)) {
        codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
    } else {
        codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
    }
    response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
    ServletOutputStream out = response.getOutputStream();
    workbook.write(out);
    out.flush();
}