public final class ExcelColumnCollection extends ExcelRowColumnCollectionBaseGeneric<ExcelColumn>
ExcelColumn
).
Note that the cells are internally allocated in rows and not in columns. ExcelColumn objects are created only if they have non-standard width or style, or they are accessed directly. So, while ExcelRowCollection.size shows number of rows occupied with data, ExcelColumnCollection.size does not say which Column is the last one occupied with data!
If you want to read all data in a sheet, use
ExcelRow.getAllocatedCells
method.
If you want to find last column occupied with data, use
ExcelWorksheet.calculateMaxUsedColumns()
method.
Following code shows how to get hidden columns and shows how to get number of columns occupied with data.
for (ExcelColumn column : ws.getColumns()) {
// Writes hidden columns
if (column.isHidden())
System.out.println("Column '" + ExcelColumnCollection.columnIndexToName(column.getIndex()) + "' is hidden");
}
// Counts used columns (columns that contain some data)
System.out.println("Number of used columns is: " + ws.calculateMaxUsedColumns());
Modifier and Type | Method and Description |
---|---|
static String |
columnIndexToName(int columnIndex)
Converts column index (0, 1, ...) to column name ("A", "B", ...).
|
static int |
columnNameToIndex(String name)
Converts column name ("A", "B", ...) to column index (0, 1, ...).
|
ExcelColumn |
get(int index)
Gets the column with the specified index.
|
void |
insertCopy(int columnIndex,
ExcelColumn sourceColumn)
Inserts copied column at the specified index.
|
void |
insertCopy(int columnIndex,
int columnCount,
ExcelColumn sourceColumn)
Inserts specified number of copied columns at the specified index.
|
void |
insertEmpty(int columnIndex)
Inserts empty column at the specified index.
|
void |
insertEmpty(int columnIndex,
int columnCount)
Inserts specified number of empty columns at the specified index.
|
void |
remove(int columnIndex)
Removes the column with the specified index.
|
void |
remove(int columnIndex,
int columnCount)
Removes specified number of columns starting at the specified index.
|
get, iterator, size
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static String columnIndexToName(int columnIndex)
columnIndex
- Column index.public static int columnNameToIndex(String name)
name
- Column name.public ExcelColumn get(int index)
get
in class ExcelRowColumnCollectionBaseGeneric<ExcelColumn>
index
- The zero-based index of the column.public void insertCopy(int columnIndex, ExcelColumn sourceColumn)
columnIndex
- The zero-based index of the column.sourceColumn
- Source column to copy.public void insertCopy(int columnIndex, int columnCount, ExcelColumn sourceColumn)
columnIndex
- The zero-based index of the column.columnCount
- Number of columns to add.sourceColumn
- Source column to copy.public void insertEmpty(int columnIndex)
columnIndex
- The zero-based index of the column.public void insertEmpty(int columnIndex, int columnCount)
columnIndex
- The zero-based index of the column.columnCount
- Number of columns to add.public void remove(int columnIndex)
columnIndex
- The zero-based index of the column.public void remove(int columnIndex, int columnCount)
columnIndex
- The zero-based index of the column.columnCount
- Number of columns to remove.© GemBox d.o.o. — All rights reserved.