public static int nextFreeColNumber(WritableSheet sheet) { if (sheet == null) return 0; int colCount = sheet.getColumns(); Cell[] cells; int i = 0; for (; i < colCount; i++) { cells = sheet.getColumn(i); for (Cell cell : cells) { if (cell.getContents() == null || cell.getContents().isEmpty()) return i; } } return i; }