ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 /** * <b>方法描述:</b> 取Excel列数据 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:12:10 <br/> * * @param workBook * 入参|Excel对象|{@link Object} * @param sheet * 入参|工作簿索引或名称|{@link java.lang.String} * @param col * 入参|列索引|{@link int} * @param coldata * 出参|列数据|{@link java.util.List} * @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:12:10") @InParams(param = { @Param(name = "workBook", comment = "Excel对象", type = Object.class), @Param(name = "sheet", comment = "工作簿索引或名称", type = java.lang.String.class), @Param(name = "col", comment = "列索引", type = int.class) }) @OutParams(param = { @Param(name = "coldata", comment = "列数据", type = java.util.List.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_xlsGetColData(Object workBook, String sheet, int col) { if (!(workBook instanceof Workbook)) { ResultBase.newFailureResult("TPTF0005", "输入Excel对象不正确,不是Workbook 对象"); } Workbook xlsObj = (Workbook) workBook; int nSheet = -1; try { nSheet = Integer.parseInt(sheet); } catch (Exception ex) { // AppLog.error(ex); AppLog.info("组件 输入参数sheet 不是数字,按照名称进行获取"); // return ResultBase.newExceptionResult("TPTF0006", "sheet 参数不是 数字:" // + sheet); } Sheet sheetObj = ((nSheet > -1) ? xlsObj.getSheetAt(nSheet) : xlsObj .getSheet(sheet)); if (sheetObj == null) { return ResultBase.newFailureResult("TPTF0007", "找不到指定的工作簿,sheet=" + sheet); } int rownum = sheetObj.getPhysicalNumberOfRows(); // jxl.Cell[] cells = sheetObj.getColumn(col); java.util.List<Object> listRet = new java.util.LinkedList<Object>(); for (int i = 0; i < rownum; i++) { Row row = sheetObj.getRow(i); if (row.getPhysicalNumberOfCells() > col) { listRet.add(getCellFormatValue(row.getCell(col))); } else { listRet.add(""); } } return ResultBase.newSuccessResult(listRet); } 交易中组件使用方式: ![](https://img.kancloud.cn/38/25/3825ca75447d50337e5cfd09489bf197_950x750.jpg) ## 参数说明及示例 Excel对象:Excel对象,可以由其他技术组件传递,示例: `__INNER__["wb"]` 工作簿索引或名称:sheet名称或者索引,示例: `"sheet1"` 列索引:指定,示例: `3` 列数据:返回指定列对象的数据集合,示例: `__INNER__["cell"]` > 获取Excel指定列数据