Java Code Examples for com.alibaba.excel.support.ExcelTypeEnum#XLSX
The following examples show how to use
com.alibaba.excel.support.ExcelTypeEnum#XLSX .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuleBatchServiceImpl.java From Qualitis with Apache License 2.0 | 6 votes |
private void writeExcelToOutput(List<ExcelTemplateRule> templateRules, List<ExcelCustomRule> customRules, List<ExcelMultiTemplateRule> multiTemplateRules, 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, ExcelTemplateRule.class); templateSheet.setSheetName(ExcelSheetName.TEMPLATE_RULE_NAME); writer.write(templateRules, templateSheet); Sheet customSheet = new Sheet(2, 0, ExcelCustomRule.class); customSheet.setSheetName(ExcelSheetName.CUSTOM_RULE_NAME); writer.write(customRules, customSheet); Sheet multiTemplateSheet = new Sheet(3, 0, ExcelMultiTemplateRule.class); multiTemplateSheet.setSheetName(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME); writer.write(multiTemplateRules, multiTemplateSheet); writer.finish(); LOGGER.info("Finish to write excel"); } catch (Exception e) { throw new WriteExcelException(e.getMessage()); } finally { outputStream.close(); } }
Example 2
Source File: ExportExcelUtil.java From SpringBoot-Home with Apache License 2.0 | 6 votes |
/** * 异步导出 Excel :一个 sheet,带表头 * * @param * @param list 数据 list,每个元素为一个 BaseRowModel * @param sheetName 导入文件的 sheet 名 * @param sheetName 导入文件的 sheet 名 * @param object 映射实体类,Excel 模型 */ public static String asyWriteExcel(List<? extends BaseRowModel> list, String sheetName, BaseRowModel object) { // 现将数据导出excel到本地 try { String fileName = URLEncoder.encode(createFileName(), "UTF-8"); ExcelWriter writer = new ExcelWriter(getFileOutputStream(fileName), ExcelTypeEnum.XLSX); Sheet sheet = new Sheet(1, 0, object.getClass()); sheet.setSheetName(sheetName); writer.write(list, sheet); writer.finish(); // 读取该excel,并上传到oss,返回下载链接 // File file = readFileByLines(fileName + ".xlsx"); // return FileUploadUtil.upload(file, fileName + ".xlsx"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("创建excel失败!"); } return null; }
Example 3
Source File: ProjectBatchServiceImpl.java From Qualitis with Apache License 2.0 | 5 votes |
private void writeExcelToOutput(List<ExcelProject> excelProjects, List<ExcelTemplateRuleByProject> excelTemplateRuleByProjects, List<ExcelCustomRuleByProject> excelCustomRuleByProjects, List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRuleByProjects, 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); writer.finish(); LOGGER.info("Finish to write excel"); } catch (Exception e) { throw new WriteExcelException(e.getMessage()); } finally { outputStream.close(); } }
Example 4
Source File: ExportExcelUtil.java From SpringBoot-Home with Apache License 2.0 | 5 votes |
/** * 导出 Excel :一个 sheet,带表头 * * @param response HttpServletResponse * @param list 需要导出的数据 * @param fileName 导出的文件名 * @param sheetName 导入文件的 sheet 名 * @param object 映射实体类,Excel 模型 */ public static void writeExcel(HttpServletResponse response, List<? extends BaseRowModel> list, String fileName, String sheetName, BaseRowModel object) { // WriteModel 是 写入 Excel 的数据模型对象 ExcelWriter writer = new ExcelWriter(getOutputStream(fileName, response), ExcelTypeEnum.XLSX); Sheet sheet = new Sheet(1, 0, object.getClass()); sheet.setSheetName(sheetName); // 异常处理 writer.write(list, sheet); writer.finish(); }
Example 5
Source File: HeadReadTest.java From easyexcel with Apache License 2.0 | 5 votes |
@Test public void testread() throws Exception { FileInputStream fileInputStream = new FileInputStream("D://test/t1.xlsx"); ExcelReader excelReader = new ExcelReader(fileInputStream, ExcelTypeEnum.XLSX, null, new TestListener()); excelReader.read(); }
Example 6
Source File: ExportExcelUtil.java From SpringBoot-Home with Apache License 2.0 | 3 votes |
/** * 导出 Excel :多个 sheet,带表头 * * @param response HttpServletResponse * @param list 需要导出的数据 list * @param fileName 导出的文件名 * @param sheetName 导入文件的 sheet 名 * @param object 映射实体类,Excel 模型 */ public static ExcelWriterFactory writeExcelWithSheets(HttpServletResponse response, List<? extends BaseRowModel> list, String fileName, String sheetName, BaseRowModel object) { ExcelWriterFactory writer = new ExcelWriterFactory(getOutputStream(fileName, response), ExcelTypeEnum.XLSX); Sheet sheet = new Sheet(1, 0, object.getClass()); sheet.setSheetName(sheetName); writer.write(list, sheet); return writer; }