4 changed files with 202 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||
|
package com.elink.esua.epdc.commons.tools.utils; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author songyunpeng |
||||
|
* @Description excel导出模板的下拉列表实体 |
||||
|
* @create 2020-09-03 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ExcelSelectionDto { |
||||
|
/** |
||||
|
* sheet页索引 0开始 |
||||
|
*/ |
||||
|
private Integer sheetIndex; |
||||
|
/** |
||||
|
* 区域中第一个单元格的列号 (下标0开始) |
||||
|
*/ |
||||
|
private Integer firstCol; |
||||
|
/** |
||||
|
* 区域中最后一个单元格的列号 |
||||
|
*/ |
||||
|
private Integer lastCol; |
||||
|
/** |
||||
|
* 下拉数据 |
||||
|
*/ |
||||
|
private String[] excelSelections; |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
package com.elink.esua.epdc.commons.tools.utils; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import java.io.*; |
||||
|
|
||||
|
/** |
||||
|
* 接收文件转化File |
||||
|
* Created by liuhongwei on 2019/6/21. |
||||
|
*/ |
||||
|
public class StreamUtils { |
||||
|
|
||||
|
|
||||
|
|
||||
|
public static File conversionFile(MultipartFile file){ |
||||
|
|
||||
|
File toFile =null; |
||||
|
InputStream ins = null; |
||||
|
try { |
||||
|
// 转化字节流
|
||||
|
ins = file.getInputStream(); |
||||
|
// 获取文件名字
|
||||
|
toFile = new File(file.getOriginalFilename()); |
||||
|
// 字节转化文件
|
||||
|
inputStreamToFile(ins, toFile); |
||||
|
ins.close(); |
||||
|
} catch (IOException e) { |
||||
|
new RenException(500,"文件转化失败"); |
||||
|
} |
||||
|
return toFile; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 流转化 |
||||
|
* @param ins file |
||||
|
* @return |
||||
|
* @author liuhongwei |
||||
|
* @date 2019/6/14 14:07 |
||||
|
*/ |
||||
|
public static void inputStreamToFile(InputStream ins, File file) { |
||||
|
try { |
||||
|
OutputStream os = new FileOutputStream(file); |
||||
|
int bytesRead = 0; |
||||
|
byte[] buffer = new byte[8192]; |
||||
|
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { |
||||
|
os.write(buffer, 0, bytesRead); |
||||
|
} |
||||
|
os.close(); |
||||
|
ins.close(); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue