🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 组件源码 /** * <b>方法描述:</b> 取Excel行列数 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:14:45 <br/> * * @param workBook * 入参|Excel对象|{@link Object} * @param sheet * 入参|Excel表单|{@link java.lang.String} * @param rows * 出参|行数|{@link int} * @param cols * 出参|列数|{@link int} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "取Excel行列数", style = "判断型", type = "同步组件", comment = "获取Excel表格指定sheet页的行数和列数", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 05:14:45") @InParams(param = { @Param(name = "workBook", comment = "Excel对象", type = Object.class), @Param(name = "sheet", comment = "Excel表单", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "rows", comment = "行数", type = int.class), @Param(name = "cols", comment = "列数", type = int.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_xlsGetSize(Object workBook, String sheet) { if (workBook == null || !(workBook instanceof Workbook)) { return ResultBase.newFailureResult("TPTF0013", "输入Excel对象不正确,不是Workbook 对象"); } Workbook xlsObj = (Workbook) workBook; int nSheet = -1; try { nSheet = Integer.parseInt(sheet); } catch (Exception ex) { AppLog.info("组件 输入参数sheet 不是数字,按照名称进行获取"); } Sheet sheetObj = ((nSheet > -1) ? xlsObj.getSheetAt(nSheet) : xlsObj .getSheet(sheet)); if (sheetObj == null) { return ResultBase.newFailureResult("TPTF0015", "找不到指定的工作簿,sheet=" + sheet); } int rows = sheetObj.getPhysicalNumberOfRows(); int cols = sheetObj.getRow(0).getPhysicalNumberOfCells(); return ResultBase.newSuccessResult(rows, cols); } 交易中组件使用方式: ![](https://img.kancloud.cn/65/f3/65f332fa5f5229e2fc9524aa9e03fbf9_950x750.jpg) ## 参数说明及示例 Excel表格对象:Excel对象,可以由其他技术组件传递,示例: `__INNER__["wb"]` Excel表单:sheet名称或者索引,示例: `"sheet1"` 行数:返回指定sheet页行数,示例: `__INNER__["row"]` 列数:返回指定sheet页列数,示例: `__INNER__["cell"]` > 获取Excel表格指定sheet页的行数和列数