Open haoyualways opened 2 years ago
private void exportListData(Map<String, Object> map){ FileInputStream ins = null; FileOutputStream out = null; try { ins = new FileInputStream(UserInfoExportConstant.TEMPLATE_PATH); IXDocReport report = XDocReportRegistry.getRegistry().loadReport(ins, TemplateEngineKind.Freemarker);
IContext context = report.createContext(); FieldsMetadata fieldsMetadata = report.createFieldsMetadata(); for (String key : map.keySet()) { ArrayList<?> list = (ArrayList) map.get(key); if (CollectionUtil.isNotEmpty(list)){ Class<?> clazz = list.get(0).getClass(); fieldsMetadata.load(key,clazz,true); } context.put(key,map.get(key)); } File file = new File(UserInfoExportConstant.TEMPORARY_FILES_PATH); File parentFile = file.getParentFile(); if ( !parentFile.exists() ){ if (parentFile.mkdirs()) { log.warn("mkdirs"+ parentFile.getAbsolutePath()); } } out = new FileOutputStream(file); report.process(context,out); log.info("导出List数据成功...保存路径为:{}",UserInfoExportConstant.TEMPORARY_FILES_PATH); }catch (Exception e){ e.printStackTrace(); }finally { try { if ( ins != null ){ ins.close(); } if ( out != null ){ out.close(); } }catch (IOException e){ log.error("操作流时发生异常,{}",e.getMessage()); } } }
@mishadoff @pascalleclercq @xylo @tiry
Could you explain your problem please?
你用OutputStream2InputStream 这个类就可以了
private void exportListData(Map<String, Object> map){ FileInputStream ins = null; FileOutputStream out = null; try { ins = new FileInputStream(UserInfoExportConstant.TEMPLATE_PATH); IXDocReport report = XDocReportRegistry.getRegistry().loadReport(ins, TemplateEngineKind.Freemarker);