<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
public static void exportExcel(List<Map<String, Object>> list,String[] str,String filePath,String fileName){
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFRow xssfRow = sheet.createRow(0);
str= new String[]{"work_time_id", "device_id", "device_name", "device_status", "recent_work_time", "total_work_time", "create_time", "remark"};
for (int i = 0; i < str.length; i++) {
xssfRow.createCell(i).setCellValue(str[i]);
}
for (int i = 0; i < list.size(); i++) {
XSSFRow row = sheet.createRow(i+1);
for (int j = 0; j <str.length; j++) {
if(list.get(i).containsKey(str[j])){
row.createCell(j).setCellValue(list.get(i).get(str[j]).toString());
}
}
}
try {
FileOutputStream out = new FileOutputStream(filePath + fileName+ ".xlsx");
workbook.write(out);
out.close();
}catch (Exception e){
}
}