##### 2.3.7 Excel多Sheet导出 目前单Sheet和单Class的方式比较多,对于多Sheet的方式还是一片空白,这里做一下说明: 导出基本采用ExportParams 这个对象,进行参数配置; 我们需要进行多Sheet导出,那么就需要定义一个基础配置对象 ~~~ public class ExportView { public ExportView(){ } private ExportParams exportParams; private List<?> dataList; private Class<?> cls; public ExportParams getExportParams() { return exportParams; } public void setExportParams(ExportParams exportParams) { this.exportParams = exportParams; } public Class<?> getCls() { return cls; } public void setCls(Class<?> cls) { this.cls = cls; } public List<?> getDataList() { return dataList; } public void setDataList(List<?> dataList) { this.dataList = dataList; } public ExportView(Builder builder) { this.exportParams = builder.exportParams; this.dataList = builder.dataList; this.cls = builder.cls; } public static class Builder { private ExportParams exportParams=null; private List<?> dataList=null; private Class<?> cls=null; public Builder() { } public Builder exportParams(ExportParams exportParams) { this.exportParams = exportParams; return this; } public Builder dataList(List<?> dataList) { this.dataList = dataList; return this; } public Builder cls(Class<?> cls) { this.cls = cls; return this; } public ExportView create() { return new ExportView(this); } } } ~~~ 对象主要有三个属性: // 该注解配置的导出属性 1. ExportParams exportParams // 对应注解 class 实例对象的数据集合 2. List dataList // 对应注解的 class 3. Class cls 这里没有用泛型,因为多Sheet导出时,会引用到不同的注解对象; 定义基础配置的集合 ~~~ public class ExportMoreView { private List<ExportView> moreViewList=Lists.newArrayList(); public List<ExportView> getMoreViewList() { return moreViewList; } public void setMoreViewList(List<ExportView> moreViewList) { this.moreViewList = moreViewList; } } ~~~ 最后在实现调用的方法中,对整个集合进行配置和解析 ~~~ List<Map<String, Object>> exportParamList=Lists.newArrayList(); //该行主要用于获取业务数据,请根据具体的情况进行修改和调整 ExportMoreView moreView=this.getBaseTransferService().mergeExportView(templateTypeCode); //迭代导出对象,将对应的配置信息写入到实际的配置中 for(ExportView view:moreView.getMoreViewList()){ Map<String, Object> valueMap=Maps.newHashMap(); valueMap.put(NormalExcelConstants.PARAMS,view.getExportParams()); valueMap.put(NormalExcelConstants.DATA_LIST,view.getDataList()); valueMap.put(NormalExcelConstants.CLASS,view.getCls()); exportParamList.add(valueMap); } //实现导出配置 modelMap.put(NormalExcelConstants.FILE_NAME,new DateTime().toString("yyyyMMddHHmmss")); //将转换完成的配置接入到导出中 modelMap.put(NormalExcelConstants.MAP_LIST,exportParamList); return NormalExcelConstants.JEECG_EXCEL_VIEW; ~~~ 如果不是采用的MVC的方式,请将转换的配置采用以下的方式实现: 参见ExcelExportUtil ![](https://static.oschina.net/uploads/space/2017/1128/111045_9s7X_2343396.png)