use of com.alibaba.excel.ExcelReader in project kapcb-common by kapbc.
the class AnalyzeUtil method analyzeExcel.
/**
* analyze excel
*
* @param docPath String
* @param headRowNumber Integer
* @param modelClazz Class<? extends M>
* @param analyzeListener T
* @param <M> <M>
* @param <T> <T>
* @return T
*/
public static <M, T extends AnalysisEventListener<M>> T analyzeExcel(String docPath, Integer headRowNumber, Class<? extends M> modelClazz, T analyzeListener) {
if (StringUtils.isBlank(docPath)) {
throw new IllegalArgumentException("analyze excel param error, the doc path is : {}" + docPath);
}
String fileName = FileUtil.getPath() + docPath;
InputStream inputStream = null;
try {
inputStream = new FileInputStream(fileName);
} catch (FileNotFoundException e) {
log.error("analyze excel get io stream error, error message is : {}", e.getMessage());
}
ExcelReaderBuilder read = EasyExcelFactory.read(inputStream, modelClazz, analyzeListener);
if (Objects.nonNull(headRowNumber)) {
read.headRowNumber(headRowNumber);
}
ExcelReader build = read.build();
build.readAll();
build.finish();
return analyzeListener;
}
use of com.alibaba.excel.ExcelReader in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method partitionByRuleName.
private ExcelRuleListener partitionByRuleName(InputStream inputStream) {
ExcelRuleListener listener = new ExcelRuleListener();
ExcelReader excelReader = new ExcelReader(inputStream, null, listener);
List<Sheet> sheets = excelReader.getSheets();
for (Sheet sheet : sheets) {
if (sheet.getSheetName().equals(ExcelSheetName.TEMPLATE_RULE_NAME)) {
sheet.setClazz(ExcelTemplateRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
} else if (sheet.getSheetName().equals(ExcelSheetName.CUSTOM_RULE_NAME)) {
sheet.setClazz(ExcelCustomRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
} else if (sheet.getSheetName().equals(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME)) {
sheet.setClazz(ExcelMultiTemplateRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
} else if (sheet.getSheetName().equals(ExcelSheetName.TEMPLATE_FILE_RULE_NAME)) {
sheet.setClazz(ExcelTemplateFileRuleByProject.class);
sheet.setHeadLineMun(1);
excelReader.read(sheet);
}
}
return listener;
}
use of com.alibaba.excel.ExcelReader in project WorkHelperApp by hubme.
the class TranslationSample method read1.
private static void read1() {
ExcelReader excelReader = EasyExcel.read(EXCEL_FILE_PATH, IndexOrNameData.class, new DemoDataListener()).build();
ReadSheet readSheet = EasyExcel.readSheet(SHEET_NAME).build();
excelReader.read(readSheet);
excelReader.finish();
}
use of com.alibaba.excel.ExcelReader in project springboot by lbshold.
the class CoordinateExcelController method convertCoordinate.
/**
* 1, 读取Excel中的坐标数据
* 2. 遍历坐标数据,
* a. 坐标数据格式转换,度分秒、度分转度
* b. 坐标数据经纬度格式转换,WGS84转GCJ02
*/
private List<MyCoordinate> convertCoordinate(@RequestParam("file") MultipartFile file) throws IOException {
// 读取Excel中的坐标数据
ExcelListener listener = new ExcelListener();
ExcelReader excelReader = new ExcelReader(file.getInputStream(), ExcelTypeEnum.XLSX, null, listener);
excelReader.read(new Sheet(1, 1, MyCoordinate.class));
List<MyCoordinate> datas = listener.getDatas();
Pattern pattern = Pattern.compile(REGEX);
Pattern pattern2 = Pattern.compile(REGEX2);
Pattern pattern3 = Pattern.compile(REGEX3);
List<MyCoordinate> result = new ArrayList<>();
String lat;
String lng;
// 遍历坐标数据
for (MyCoordinate myCoordinate : datas) {
lat = myCoordinate.getLatitude();
lng = myCoordinate.getLongitude();
if (StringUtils.isEmpty(lat) || StringUtils.isEmpty(lng) || StringUtils.isEmpty(lat.trim()) || StringUtils.isEmpty(lng.trim())) {
myCoordinate.setRemark("数据不能为空");
myCoordinate.setIsSucceeded(FALSE);
result.add(myCoordinate);
continue;
}
lat = lat.trim();
lng = lng.trim();
if (pattern.matcher(lat).find() && pattern2.matcher(lng).find()) {
myCoordinate.setLongitude(CoordinateFormatUtil.DmsTurnDD(lat));
myCoordinate.setLatitude(CoordinateFormatUtil.DmsTurnDD(lng));
myCoordinate.setIsSucceeded(TRUE);
result.add(MyUitls.wgs84ToGcj02Copy(myCoordinate));
continue;
}
if (pattern2.matcher(lat).find() && pattern2.matcher(lng).find()) {
myCoordinate.setLongitude(CoordinateFormatUtil.DmTurnDD(lat));
myCoordinate.setLatitude(CoordinateFormatUtil.DmTurnDD(lng));
myCoordinate.setIsSucceeded(TRUE);
result.add(MyUitls.wgs84ToGcj02Copy(myCoordinate));
continue;
}
if (pattern3.matcher(lat).find() && pattern3.matcher(lng).find()) {
myCoordinate.setIsSucceeded(TRUE);
result.add(MyUitls.wgs84ToGcj02Copy(myCoordinate));
continue;
}
myCoordinate.setIsSucceeded(FALSE);
myCoordinate.setRemark("数据格式有误");
result.add(myCoordinate);
}
return result;
}
use of com.alibaba.excel.ExcelReader in project SpringBoot-Hello by ruiyeclub.
the class ExcelUtil method readExcel.
/**
* @param inputStream Excel的输入流
* @param excelTypeEnum Excel的格式(XLS或XLSX)
* @Description: 使用 StringList 来读取Excel
* @Date: 2020/1/16 21:40
* @Return: java.util.List<java.util.List < java.lang.String>>
* @Throws: Exception
*/
public static List<List<String>> readExcel(InputStream inputStream, ExcelTypeEnum excelTypeEnum) throws Exception {
StringExcelListener listener = new StringExcelListener();
ExcelReader excelReader = new ExcelReader(inputStream, excelTypeEnum, null, listener);
excelReader.read();
return listener.getDatas();
}
Aggregations