🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 组件源码 /** * <b>方法描述:</b> 打开Excel文件 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:11:28 <br/> * * @param fileName * 入参|文件名|{@link java.lang.String} * @param workBook * 出参|工作簿|{@link Object} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "打开Excel文件", style = "判断型", type = "同步组件", comment = "打开EXCEL文件,返回workbook对象,需要注意,如果是大文件存在性能问题。应采用流式读取", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 05:11:28") @InParams(param = { @Param(name = "fileName", comment = "文件名", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "workBook", comment = "工作簿", type = Object.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功") }) public static ResultBase P_xlsOpen(String fileName) { File xlsFile = new File(fileName); try { InputStream is = new FileInputStream(fileName); if (fileName.toLowerCase().endsWith(".xls")) { return ResultBase.newSuccessResult(new HSSFWorkbook(is)); } else { return ResultBase.newSuccessResult(new XSSFWorkbook(is)); } } catch (Exception ex) { AppLog.error(ex); return ResultBase.newExceptionResult("TPTF0004", "打开Excel文件" + fileName + "异常" + AppLog.errorMsg(ex)); } } 交易中组件使用方式: ![](https://img.kancloud.cn/5e/bd/5ebd1281e76d753de69ab747c63a5c77_950x750.jpg) ## 参数说明及示例 文件名:文件全路径,示例: `"/home/usr/local/test.xls"` 工作簿:工作簿对象,示例: `__INNER__["wb"]` > 打开EXCEL文件,返回workbook对象,需要注意,如果是大文件存在性能问题。应采用流式读取