public void exportSheetUsers () {
List <GysuserAndagentVo> users=new ArrayList <> ();
List <GysexcelAgents> agents=new ArrayList <> ();
Workbook workBook=null;
try {
ExportParams userExportParams=new ExportParams ( );
userExportParams.setSheetName ( "用户表" );
userExportParams.setTitle ( "用户列表" );
Map <String, Object> userExportMap=new HashMap <> ( );
userExportMap.put ( "title", userExportParams );
userExportMap.put ( "entity", GysuserAndagentVo.class );
userExportMap.put ( "data", users );
ExportParams logInfoExportParams=new ExportParams ( );
logInfoExportParams.setTitle ( "关系表" );
logInfoExportParams.setSheetName ( "关系" );
Map <String, Object> logInfoExportMap=new HashMap <> ( );
logInfoExportMap.put ( "title", logInfoExportParams );
logInfoExportMap.put ( "entity", GysexcelAgents.class );
logInfoExportMap.put ( "data", agents );
List <Map <String, Object>> sheetsList=new ArrayList <> ( );
sheetsList.add ( userExportMap );
sheetsList.add ( logInfoExportMap );
workBook=ExcelExportUtil.exportExcel ( sheetsList, ExcelType.HSSF );
String path1=path + "/excel/" ;
String fillname=userCode + euuid + ".xlsx";
File myPath = new File(path1);
log.info ( "文件夹路径:"+path1+fillname );
if ( !myPath.exists()){
boolean mkdir=myPath.mkdir ( );
log.info("创建文件夹路径为:"+ path1+fillname);
}
FileOutputStream out=new FileOutputStream ( path1+fillname );
workBook.write ( out );
workBook.close ( );
} catch (Exception e) {
e.printStackTrace ( );
} finally {
if (workBook != null) {
try {
workBook.close ( );
} catch (IOException e) {
e.printStackTrace ( );
}
}
}
}
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>