use of com.alibaba.excel.ExcelWriter 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();
}
}
use of com.alibaba.excel.ExcelWriter 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();
}
}
use of com.alibaba.excel.ExcelWriter in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method writeExcelFile.
private void writeExcelFile(File tmpFile, List<String> tables, UploadResultRequest request) throws UnExpectedRequestException {
int sheetNo = 1;
OutputStream tmpOutputStream = null;
try {
Path parentPath = Paths.get(tmpFile.getParent());
if (Files.notExists(parentPath)) {
tmpFile.getParentFile().mkdirs();
}
if (!tmpFile.exists()) {
LOGGER.info("Start to create local file.");
tmpFile.createNewFile();
}
tmpOutputStream = new FileOutputStream(tmpFile);
ExcelWriter writer = new ExcelWriter(tmpOutputStream, ExcelTypeEnum.XLSX, true);
// Find task with the start time and end time.
for (String tableName : tables) {
List<Task> tasks = taskDao.findWithSubmitTimeAndDatasource(request.getStartTime(), request.getEndTime(), request.getClusterName(), request.getDatabaseName(), tableName);
List<TaskRuleSimple> taskRuleSimples = tasks.stream().map(Task::getTaskRuleSimples).flatMap(taskRuleSimpleSet -> taskRuleSimpleSet.stream()).distinct().collect(Collectors.toList());
// Generate analysis result excel
List<ExcelResult> results = new ArrayList<>(taskRuleSimples.size());
for (TaskRuleSimple taskRuleSimple : taskRuleSimples) {
ExcelResult excelResult = new ExcelResult();
excelResult.setRuleName(taskRuleSimple.getRuleName());
excelResult.setClusterName(request.getClusterName());
excelResult.setDatabaseName(request.getDatabaseName());
excelResult.setTableName(tableName);
excelResult.setBeginTime(taskRuleSimple.getTask().getBeginTime());
excelResult.setEndTime(taskRuleSimple.getTask().getEndTime());
StringBuffer checkTemplateStr = new StringBuffer();
StringBuffer resultStr = new StringBuffer();
joinAlarmConfig(results, taskRuleSimple, excelResult, request, checkTemplateStr, resultStr);
results.add(excelResult);
}
Sheet templateSheet = new Sheet(sheetNo++, 0, ExcelResult.class);
templateSheet.setSheetName(tableName + "-" + ExcelSheetName.ANALYSIS_NAME);
writer.write(results, templateSheet);
}
writer.finish();
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage(), e);
throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
} finally {
try {
tmpOutputStream.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
use of com.alibaba.excel.ExcelWriter in project ballcat by ballcat-projects.
the class ManySheetWriteHandler method write.
@Override
public void write(Object obj, HttpServletResponse response, ResponseExcel responseExcel) {
List<?> objList = (List<?>) obj;
ExcelWriter excelWriter = getExcelWriter(response, responseExcel);
Sheet[] sheets = responseExcel.sheets();
WriteSheet sheet;
for (int i = 0; i < sheets.length; i++) {
List<?> eleList = (List<?>) objList.get(i);
Class<?> dataClass = eleList.get(0).getClass();
// 创建sheet
sheet = this.sheet(sheets[i], dataClass, responseExcel.template(), responseExcel.headGenerator());
// 写入sheet
excelWriter.write(eleList, sheet);
}
excelWriter.finish();
}
use of com.alibaba.excel.ExcelWriter in project ballcat by ballcat-projects.
the class SingleSheetWriteHandler method write.
@Override
public void write(Object obj, HttpServletResponse response, ResponseExcel responseExcel) {
List<?> list = (List<?>) obj;
ExcelWriter excelWriter = getExcelWriter(response, responseExcel);
// 有模板则不指定sheet名
Class<?> dataClass = list.get(0).getClass();
WriteSheet sheet = this.sheet(responseExcel.sheets()[0], dataClass, responseExcel.template(), responseExcel.headGenerator());
excelWriter.write(list, sheet);
excelWriter.finish();
}
Aggregations