Search in sources :

Example 11 with ExcelReader

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;
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelReaderBuilder(com.alibaba.excel.read.builder.ExcelReaderBuilder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream)

Example 12 with ExcelReader

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;
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) Sheet(com.alibaba.excel.metadata.Sheet) ExcelRuleListener(com.webank.wedatasphere.qualitis.rule.excel.ExcelRuleListener)

Example 13 with ExcelReader

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();
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet)

Example 14 with ExcelReader

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;
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) MyCoordinate(com.summit.coordinates.entity.MyCoordinate) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) ExcelListener(com.summit.coordinates.config.ExcelListener) Sheet(com.alibaba.excel.metadata.Sheet)

Example 15 with ExcelReader

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();
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) StringExcelListener(cn.ruiyeclub.listener.StringExcelListener)

Aggregations

ExcelReader (com.alibaba.excel.ExcelReader)24 ReadSheet (com.alibaba.excel.read.metadata.ReadSheet)15 Test (org.junit.Test)6 ExcelWriter (com.alibaba.excel.ExcelWriter)5 Sheet (com.alibaba.excel.metadata.Sheet)5 WriteSheet (com.alibaba.excel.write.metadata.WriteSheet)5 FileInputStream (java.io.FileInputStream)4 WriteTable (com.alibaba.excel.write.metadata.WriteTable)3 ArrayList (java.util.ArrayList)3 MapCache (com.alibaba.excel.cache.MapCache)2 AnalysisContext (com.alibaba.excel.context.AnalysisContext)2 SyncReadListener (com.alibaba.excel.event.SyncReadListener)2 ExcelReaderBuilder (com.alibaba.excel.read.builder.ExcelReaderBuilder)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 ModelExcelListener (cn.ruiyeclub.listener.ModelExcelListener)1 StringExcelListener (cn.ruiyeclub.listener.StringExcelListener)1 SimpleData (com.alibaba.easyexcel.test.core.simple.SimpleData)1 TestFileUtil (com.alibaba.easyexcel.test.util.TestFileUtil)1 EasyExcel (com.alibaba.excel.EasyExcel)1