We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unexpected column count


Using Aspose Cells for Java, version 21.12.

Sample code:

Workbook workbook = new Workbook("S.02.01.02 annex.xlsx");
Worksheet worksheet = workbook.getWorksheets().get("Builder Info");
Cells cells = worksheet.getCells();
System.out.println("cells.getMaxColumn() = " + cells.getMaxColumn());
System.out.println("cells.getMaxDataColumn() = " + cells.getMaxDataColumn());
ColumnCollection columns = cells.getColumns();
System.out.println("cells.getColumns().getCount() = " + columns.getCount());

Input file:
S.02.01.02 annex.zip (54.4 KB)


cells.getMaxColumn() = 2
cells.getMaxDataColumn() = 2
cells.getColumns().getCount() = 0

We do not understand, why cells.getColumns().getCount() returns 0, as there clearly are columns in the sheet in question.

Thanks in advance,


This ColumnCollection.getCount() attribute which will give you the total of the columns which are initialized. So, you should always rely on getMaxDataColumn()/getMaxColumn() methods.

Hi @Amjad_Sahi,

Could you explain, what you mean by “initialized”?

Note also, that the same methods for rows are behaving as expected.

Thanks in advance,


I am able to reproduce the issue as you mentioned. I found an unexpected behavior for cells.getColumns().getCount() attribute which gives “0” instead of 1. I also found cells.getRows().getCount() gives “1” which is expected. I have logged a ticket with an id “CELLSJAVA-44155” for your issue. We will evaluate the issue and figure it out soon.

Once we have an update on it, we will let you know.


We evaluated your issue further. This is not an issue with the APIs.
Please note, ColumnCollection contains the Column objects which represent the settings of one column in a worksheet. The settings include column width and style that need to be applied to the whole column, .etc. Just like, RowCollection, when you call ColumnCollection[columnIndex]:
if the corresponding Column object exists in the collection, then this Column object will be returned.
Otherwise one new Column object will be initialized with default settings and added to the collection, then return it to the user.

The Column object only represents the settings for a column in the worksheet, not the cells data. So, ColumnCollection.Count has nothing to do with whether there are non-empty cells in the worksheet. It is same for Column object, one initialized Column object in the collection does not mean there are non-empty cells in corresponding column. So, please always check cells data with APIs of Cells, not with ColumnCollection/Column. ColumnCollection/Column is designed for users to get/set settings only.

Even for RowCollection, its Count property does not represent that there are non-empty cells data in the worksheet or not. When a user call [rowIndex] one Row object may be instantiated and added into the collection. However, even though many Row objects have been instantiated in the collection, there might be not any cell in the row or worksheet.

Hope, this helps you to understanding the internal model.

Hi @Amjad_Sahi,

Thanks for the explanation. I would suggest to add this information to the JavaDoc, as it is far from obvious.

Kind regards,


Yes, sure, we have already planned to update (we will provide more details) the description of the relevant APIs in the Docs/API Reference Pages.