Search in sources :

Example 1 with Sheet

use of com.alibaba.excel.metadata.Sheet in project springboot by lbshold.

the class CoordinateExcelController method template.

@ApiOperation("Excel导入模板下载")
@GetMapping("/not-auth/template")
public void template(HttpServletResponse response) throws Exception {
    List<MyCoordinate> result = new ArrayList<>();
    response.setCharacterEncoding("UTF-8");
    String name = URLEncoder.encode("坐标转换模板.xlsx", "UTF-8");
    response.setContentType("application/x-msdownload");
    response.addHeader("Content-Disposition", "attachment;filename*=utf-8'zh_cn'" + name);
    try (OutputStream out = response.getOutputStream()) {
        ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);
        Sheet sheet1 = new Sheet(1, 0, MyCoordinate2.class);
        sheet1.setSheetName("坐标转换模板");
        writer.write(result, sheet1);
        writer.finish();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : MyCoordinate(com.summit.coordinates.entity.MyCoordinate) OutputStream(java.io.OutputStream) ExcelWriter(com.alibaba.excel.ExcelWriter) ArrayList(java.util.ArrayList) Sheet(com.alibaba.excel.metadata.Sheet) IOException(java.io.IOException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with Sheet

use of com.alibaba.excel.metadata.Sheet in project springboot by lbshold.

the class CoordinateExcelController method downLoad.

@ApiOperation(value = "转换后的坐标Excel导出", notes = "Excel批量导入坐标后,复制该请求链接浏览器访问下载Excel(转换后的坐标),转换失败Excel会有相应提示")
@GetMapping("/not-auth/export")
public void downLoad(HttpServletResponse response) throws Exception {
    Cache cache = cacheManager.getCache("file");
    Cache.ValueWrapper cacheValue = cache.get("result");
    if (cacheValue != null) {
        List<MyCoordinate> result = (List<MyCoordinate>) cacheValue.get();
        // 写入excel
        response.setCharacterEncoding("UTF-8");
        String name = URLEncoder.encode("转换后的Gcj02坐标.xlsx", "UTF-8");
        response.setContentType("application/x-msdownload");
        response.addHeader("Content-Disposition", "attachment;filename*=utf-8'zh_cn'" + name);
        try (OutputStream out = response.getOutputStream()) {
            ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);
            Sheet sheet1 = new Sheet(1, 0, MyCoordinate.class);
            sheet1.setSheetName("转换后的Gcj02坐标");
            writer.write(result, sheet1);
            writer.finish();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    cache.clear();
}
Also used : MyCoordinate(com.summit.coordinates.entity.MyCoordinate) OutputStream(java.io.OutputStream) ExcelWriter(com.alibaba.excel.ExcelWriter) ArrayList(java.util.ArrayList) List(java.util.List) Sheet(com.alibaba.excel.metadata.Sheet) IOException(java.io.IOException) Cache(org.springframework.cache.Cache) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Sheet

use of com.alibaba.excel.metadata.Sheet in project Qualitis by WeBankFinTech.

the class RuleBatchServiceImpl method writeExcelToOutput.

private void writeExcelToOutput(List<ExcelTemplateRuleByProject> templateRules, List<ExcelCustomRuleByProject> customRules, List<ExcelMultiTemplateRuleByProject> multiTemplateRules, List<ExcelTemplateFileRuleByProject> templateFileRules, OutputStream outputStream) throws WriteExcelException, IOException {
    try {
        LOGGER.info("Start to write excel");
        ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);
        Sheet templateSheet = new Sheet(1, 0, ExcelTemplateRuleByProject.class);
        templateSheet.setSheetName(ExcelSheetName.TEMPLATE_RULE_NAME);
        writer.write(templateRules, templateSheet);
        Sheet customSheet = new Sheet(2, 0, ExcelCustomRuleByProject.class);
        customSheet.setSheetName(ExcelSheetName.CUSTOM_RULE_NAME);
        writer.write(customRules, customSheet);
        Sheet multiTemplateSheet = new Sheet(3, 0, ExcelMultiTemplateRuleByProject.class);
        multiTemplateSheet.setSheetName(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME);
        writer.write(multiTemplateRules, multiTemplateSheet);
        Sheet templateFileSheet = new Sheet(4, 0, ExcelTemplateFileRuleByProject.class);
        templateFileSheet.setSheetName(ExcelSheetName.TEMPLATE_FILE_RULE_NAME);
        writer.write(templateFileRules, templateFileSheet);
        writer.finish();
        LOGGER.info("Finish to write excel");
    } catch (Exception e) {
        throw new WriteExcelException(e.getMessage(), 500);
    } finally {
        outputStream.close();
    }
}
Also used : ExcelWriter(com.alibaba.excel.ExcelWriter) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Sheet(com.alibaba.excel.metadata.Sheet) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException) IOException(java.io.IOException) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) ParseException(org.apache.hadoop.hive.ql.parse.ParseException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)

Example 4 with Sheet

use of com.alibaba.excel.metadata.Sheet in project Qualitis by WeBankFinTech.

the class ProjectBatchServiceImpl method writeExcelToOutput.

private void writeExcelToOutput(List<ExcelProject> excelProjects, List<ExcelTemplateRuleByProject> excelTemplateRuleByProjects, List<ExcelCustomRuleByProject> excelCustomRuleByProjects, List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRuleByProjects, List<ExcelTemplateFileRuleByProject> excelTemplateFileRuleByProject, OutputStream outputStream) throws WriteExcelException, IOException {
    try {
        LOGGER.info("Start to write excel");
        ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);
        Sheet templateRuleSheet = new Sheet(1, 0, ExcelTemplateRuleByProject.class);
        templateRuleSheet.setSheetName(ExcelSheetName.TEMPLATE_RULE_NAME);
        writer.write(excelTemplateRuleByProjects, templateRuleSheet);
        Sheet projectSheet = new Sheet(2, 0, ExcelProject.class);
        projectSheet.setSheetName(ExcelSheetName.PROJECT_NAME);
        writer.write(excelProjects, projectSheet);
        Sheet customRuleSheet = new Sheet(3, 0, ExcelCustomRuleByProject.class);
        customRuleSheet.setSheetName(ExcelSheetName.CUSTOM_RULE_NAME);
        writer.write(excelCustomRuleByProjects, customRuleSheet);
        Sheet multiRuleSheet = new Sheet(4, 0, ExcelMultiTemplateRuleByProject.class);
        multiRuleSheet.setSheetName(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME);
        writer.write(excelMultiTemplateRuleByProjects, multiRuleSheet);
        Sheet templateFileSheet = new Sheet(5, 0, ExcelTemplateFileRuleByProject.class);
        templateFileSheet.setSheetName(ExcelSheetName.TEMPLATE_FILE_RULE_NAME);
        writer.write(excelTemplateFileRuleByProject, templateFileSheet);
        writer.finish();
        LOGGER.info("Finish to write excel");
    } catch (Exception e) {
        throw new WriteExcelException(e.getMessage());
    } finally {
        outputStream.close();
    }
}
Also used : ExcelWriter(com.alibaba.excel.ExcelWriter) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) Sheet(com.alibaba.excel.metadata.Sheet) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) ZipException(net.lingala.zip4j.exception.ZipException) RoleNotFoundException(javax.management.relation.RoleNotFoundException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) IOException(java.io.IOException) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException)

Example 5 with Sheet

use of com.alibaba.excel.metadata.Sheet in project Qualitis by WeBankFinTech.

the class ProjectBatchServiceImpl method readExcel.

private ExcelProjectListener readExcel(InputStream inputStream) {
    LOGGER.info("Start to read project excel");
    ExcelProjectListener listener = new ExcelProjectListener();
    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.PROJECT_NAME)) {
            sheet.setClazz(ExcelProject.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);
        } else if (sheet.getSheetName().equals(ExcelSheetName.RULE_METRIC_NAME)) {
            sheet.setClazz(ExcelRuleMetric.class);
            sheet.setHeadLineMun(1);
            excelReader.read(sheet);
        }
    }
    LOGGER.info("Finish to read project excel. excel content: rule sheet {}, project sheet {}", listener.getExcelRuleContent(), listener.getExcelProjectContent());
    return listener;
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelProjectListener(com.webank.wedatasphere.qualitis.project.excel.ExcelProjectListener) Sheet(com.alibaba.excel.metadata.Sheet)

Aggregations

Sheet (com.alibaba.excel.metadata.Sheet)18 ExcelWriter (com.alibaba.excel.ExcelWriter)13 IOException (java.io.IOException)8 ExcelReader (com.alibaba.excel.ExcelReader)5 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)4 WriteExcelException (com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException)4 OutputStream (java.io.OutputStream)4 ArrayList (java.util.ArrayList)4 MyCoordinate (com.summit.coordinates.entity.MyCoordinate)3 ApiOperation (io.swagger.annotations.ApiOperation)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ModelExcelListener (cn.ruiyeclub.listener.ModelExcelListener)1 BaseRowModel (com.alibaba.excel.metadata.BaseRowModel)1 Table (com.alibaba.excel.metadata.Table)1 ExcelListener (com.summit.coordinates.config.ExcelListener)1 Task (com.webank.wedatasphere.qualitis.entity.Task)1