public WCell[] getColumn(int i) { Cell[] cells = sheet.getColumn(i); if (cells == null) { return null; } WCell[] retCells = new WCell[cells.length]; for (int j = 0; j < cells.length; j++) { retCells[j] = new JxlWCellImpl(cells[j]); } return retCells; }
/** * Get a specific column from the Excel Worksheet * You can optionally skip the top row of the column to ensure column titles are not pulled into the data set * (The first column is column 1) * * @param columnNumber * @param skipFirstRow * @return * @throws Exception */ public HashMap<Integer, Cell> getColumn(int columnNumber, boolean skipFirstRow) throws Exception { if (this.selectedSheet.equals(null)) { throw new Exception("No sheet selected. You must select a sheet before trying to get data!"); } else if (columnNumber > this.selectedSheet.getColumns()) { throw new Exception("There are only " + this.selectedSheet.getColumns() + " columns in this sheet. Unable to select column " + columnNumber + "!"); } HashMap<Integer, Cell> selectedColumn = new HashMap<Integer, Cell>(); for (Cell currentCell : this.selectedSheet.getColumn(columnNumber - 1)) { selectedColumn.put(selectedColumn.size() + 1, currentCell); } if (skipFirstRow) { selectedColumn.remove(1); } return selectedColumn; }
throw new Exception("There are only " + this.selectedSheet.getRows() + " columnss in this sheet. Unable to select columns " + keyColumn + " and " + valueColumn + "!"); Cell[] hashMapKey = this.selectedSheet.getColumn(keyColumn - 1); Cell[] hashMapValue = this.selectedSheet.getColumn(valueColumn - 1); if (hashMapKey.length != hashMapValue.length) { throw new Exception("The columns supplied are different lengths, unable to map them!");