ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 /** * <b>方法描述:</b> 取Excel单元格 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:13:55 <br/> * * @param workBook * 入参|Excel表格对象|{@link Object} * @param sheet * 入参|Excel工作簿|{@link java.lang.String} * @param row * 入参|行坐标|{@link int} * @param col * 入参|列坐标|{@link int} * @param celldata * 出参|单元格数据|{@link java.lang.String} * @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:13:55") @InParams(param = { @Param(name = "workBook", comment = "Excel表格对象", type = Object.class), @Param(name = "sheet", comment = "Excel工作簿", type = java.lang.String.class), @Param(name = "row", comment = "行坐标", type = int.class), @Param(name = "col", comment = "列坐标", type = int.class) }) @OutParams(param = { @Param(name = "celldata", comment = "单元格数据", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_xlsGetCellData(Object workBook, String sheet, int row, int col) { if (workBook == null || !(workBook instanceof Workbook)) { return ResultBase.newFailureResult("TPTF0008", "输入Excel对象不正确,不是Workbook 对象"); } Workbook xlsObj = (Workbook) workBook; int nSheet = -1; try { nSheet = Integer.parseInt(sheet); } catch (Exception ex) { AppLog.info("组件 输入参数sheet 不是数字,按照名称进行获取"); // return ResultBase.newExceptionResult("TPTF0009", "类型转换错误:" + ex); } Sheet sheetObj = ((nSheet > -1) ? xlsObj.getSheetAt(nSheet) : xlsObj .getSheet(sheet)); if (sheetObj == null) { return ResultBase.newFailureResult("TPTF0010", "找不到指定的工作簿:sheet=" + sheet); } try { Row rowObj = sheetObj.getRow(row); if (rowObj == null) return ResultBase.newFailureResult("TPTF0011", "没有指定行记录,行坐标:" + row); int cols = rowObj.getPhysicalNumberOfCells(); if (col > cols) { return ResultBase.newFailureResult("TPTF0011", "没有指定列记录:列坐标超出行列数:列=" + col + ",总列数=" + cols); } return ResultBase.newSuccessResult(getCellFormatValue(rowObj .getCell(col))); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTF0012", "获取单元格对象异常:" + AppLog.errorMsg(e)); } } 交易中组件使用方式: ![](https://img.kancloud.cn/34/12/34122b53ae857d87b575dc7448f21d08_950x750.jpg) ## 参数说明及示例 Excel表格对象:Excel对象,可以由其他技术组件传递,示例: `__INNER__["wb"]` Excel工作簿:sheet名称或者索引,示例: `"sheet1"` 行坐标:指定单元格所在行,示例: `3` 列坐标:指定单元格所在列,示例: `5` 单元格数据:返回指定单元格数据对象,示例: `__INNER__["data"]` > 获取Excel单元格数据