企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 /** * <b>方法描述:</b> 取Excel行数据 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:15:27 <br/> * * @param workBook * 入参|Excel表格对象|{@link Object} * @param sheet * 入参|Excel表单|{@link java.lang.String} * @param rowno * 入参|指定行|{@link int} * @param rowdata * 出参|指定行数据|{@link com.ylink.ide.trade.runtime.context.JavaList} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "取Excel行数据", style = "判断型", type = "同步组件", comment = "获取Excel行数据", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 05:15:27") @InParams(param = { @Param(name = "workBook", comment = "Excel表格对象", type = Object.class), @Param(name = "sheet", comment = "Excel表单", type = java.lang.String.class), @Param(name = "rowno", comment = "指定行", type = int.class) }) @OutParams(param = { @Param(name = "rowdata", comment = "指定行数据", type = com.ylink.ide.trade.runtime.context.JavaList.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_xlsGetRowData(Object workBook, String sheet, int rowno) { if (workBook == null || !(workBook instanceof Workbook)) { return ResultBase.newFailureResult("TPTF0016", "输入Excel对象不正确,不是Workbook 对象"); } Workbook xlsObj = (Workbook) workBook; int nSheet = -1; try { nSheet = Integer.parseInt(sheet); } catch (Exception ex) { AppLog.info("组件 输入参数sheet 不是数字,按照名称进行获取"); // return ResultBase.newExceptionResult("TPTF0017", "类型转换错误:" + ex); } Sheet sheetObj = ((nSheet > -1) ? xlsObj.getSheetAt(nSheet) : xlsObj .getSheet(sheet)); if (sheetObj == null) { return ResultBase.newFailureResult("TPTF0018", "找不到指定的工作簿,sheet=" + sheet); } Row rowObj = sheetObj.getRow(rowno); int cols = rowObj.getPhysicalNumberOfCells(); com.ylink.ide.trade.runtime.context.JavaList listRet = new com.ylink.ide.trade.runtime.context.JavaList(); for (int i = 0; i < cols; i++) { listRet.add(getCellFormatValue(rowObj.getCell(i))); } return ResultBase.newSuccessResult(listRet); } 交易中组件使用方式: ![](https://img.kancloud.cn/3a/0a/3a0a623fef4cc24aa44d62eca9965d3a_950x750.jpg) ## 参数说明及示例 Excel表格对象:Excel对象,可以由其他技术组件传递,示例: `__INNER__["wb"]` Excel表单:sheet名称或者索引,示例: `"sheet1"` 指定行:设置获取数据的行号,示例: `5` 指定行数据:返回指定行的数据集合,示例: `__INNER__["rowData"]` > 获取Excel行数据