多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 组件源码 /** * <b>方法描述:</b> 工作簿写文件 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2019-07-18 16:41:30 <br/> * * @param filepath * 入参|文件名称|{@link java.lang.String} * @param wb * 入参|work|{@link org.apache.poi.xssf.streaming.SXSSFWorkbook} * @param filename * 出参|文件名|{@link java.lang.String} * @return 0 失败<br/> * 1 成功<br/> */ @Component(label = "工作簿写文件", style = "判断型", type = "同步组件", comment = "根据文件名称获取工作簿", version = "1.0.0", deprecated = false, author = "admin", date = "2019-07-18 04:41:30") @InParams(param = { @Param(name = "filepath", comment = "文件名称", type = java.lang.String.class), @Param(name = "wb", comment = "work", type = org.apache.poi.xssf.streaming.SXSSFWorkbook.class) }) @OutParams(param = { @Param(name = "filename", comment = "文件名", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase A_writerWorkbook(String filepath, SXSSFWorkbook wb) { FileOutputStream out = null; try { if (filepath.endsWith(".xls")) { filepath += "x"; } File file = new File(filepath); if (!file.exists()) { file.createNewFile(); } out = new FileOutputStream(filepath, false); wb.write(out); wb.dispose(); AppLog.info("写文件,size={},name={}", file.length(), file.getName()); return ResultBase.newSuccessResult(file.getName()); } catch (Exception e) { AppLog.error("写工作簿异常", e); return ResultBase.newFailureResult("999", "写文件工作簿异常:[" + filepath + "]" + AppLog.errorMsg(e)); } finally { try { wb.close(); if (out != null) out.close(); } catch (IOException e) { e.printStackTrace(); } } } 交易中组件使用方式: ![](https://img.kancloud.cn/71/e4/71e48457903f044d8d08f4b6ee177b1c_950x750.jpg) ## 参数说明及示例 文件名称:Excel文件全路径,示例: `__INNER__["file"]`或者`"/home/usr/local/test.xls"` work:需要写进去的工作簿,可以是其他技术组件获取的或者生成的工作簿,示例: `__INNER__["workBook"]` 文件名:返回Excel文件名,示例: `__INNER__["fileName"]` > 将工作簿写进文件里面