springboot导入Excel数据
标签:equals wired test sub hashmap 代码 declare xss --
只适用于没有校验的数据的导入
依赖jar包
org.apache.poi
poi
4.1.0
org.apache.poi
poi-ooxml
4.1.0
org.projectlombok
lombok
true
io.springfox
springfox-swagger-ui
2.7.0
io.springfox
springfox-swagger2
2.7.0
工具类
import io.swagger.annotations.ApiModelProperty;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class ExcelUtil {
public static final String XLS = ".xls";
public static final String XLSX = ".xlsx";
public List readExcelFileToDTO(MultipartFile file, Class clazz) throws IOException {
return readExcelFileToDTO(file, clazz, 0);
}
public List readExcelFileToDTO(MultipartFile file, Class clazz, Integer sheetId) throws IOException {
//将文件转成workbook类型
Workbook workbook = buildWorkbook(file);
//第一个表
return readSheetToDTO(workbook.getSheetAt(sheetId), clazz);
}
public List readSheetToDTO(Sheet sheet, Class clazz) throws IOException {
List result = new ArrayList();
List
转载:
原文链接:https://blog.csdn.net/p393975269/article/details/100130728
springboot导入Excel数据
标签:equals wired test sub hashmap 代码 declare xss --
原文地址:https://www.cnblogs.com/langcangsheng/p/11612440.html
评论