最近项目用到的excel上传下载,代码贴上
@Value("${download.excel.localPath:null}")
private String downLoadLocalPath;
// private String downLoadLocalPath="D:\\excel\\download";
@Value("${create.excel.localPath:null}")
private String createLoacalPath;
// private String createLoacalPath = "D:\\excel";
文件上传
/**
* excel导入,解析生成新的查询结果excel
* @return
*/
@PostMapping("/importExcel")
@ApiOperation(value = "批量数据excel导入")
public ResponseEntity<Object> importExcel(DataInterfaceQueryDto dto,@RequestParam(value = "file") MultipartFile file) {
SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhmmss");
Map<String,String> map = new HashedMap();
DataInterfaceBatchLoggerResponseDto dataInterfaceBatchLoggerResponseDto = new DataInterfaceBatchLoggerResponseDto();
try {
//接收导入文件,将byte流转成文件下载到指定路径
String createFilePath = downloadExcel(file);
String fileName = sdf.format(new Date())+"三方数据结果查询.xls";
String downLoadLocalPath1 = downLoadLocalPath+"/"+File.separator+fileName;
//判断是否创建文件夹
File dir = new File(downLoadLocalPath);
if(!dir.exists()){
dir.mkdir();
}
dataInterfaceBatchLoggerResponseDto.setFileName(fileName);
FileOutputStream outputStream = null;
//解析生成新文件
Map<String,Object> result = createResponseExcel.export(map, dataInterfaceBatchLoggerResponseDto,dto,createFilePath);
HSSFWorkbook wb = (HSSFWorkbook) result.get("wb");
DataInterfaceBatchChooseDto dataInterfaceBatchChooseDto = (DataInterfaceBatchChooseDto) result