Free Support Forum -

GetMaxColumn() gives wrong result

Attached spreadsheet, created with Aspose.Cells, gives the wrong result for


The returned value is 255 but should be 9.

workbook.getWorksheets().getActiveSheet().getCells().getRow(1) .getLastCellIndex()

gives the correct result.

What can be the problem?


Thanks for reporting the problem.

I can see the problem. Below is my code. MaxColumn is wrong but MaxDataColumn is right. I have logged this bug and we will fix it asap.

This issue has been logged as CELLSJAVA-29114.


String path=“F:\Shak-Data-RW\Downloads\WVP_out.xls”;

Workbook workbook = new Workbook();;

Worksheet worksheet = workbook.getWorksheets().getSheet(0);

int col1 = worksheet.getCells().getMaxColumn();

int col2 = worksheet.getCells().getMaxDataColumn();




It is not the bug of Cells.getMaxColumn(). This method is used to get the maximum column that has data or style(cell style, width, .etc.) defined.

In your template file, all columns have been defined(when opening your template file in ms excel, you can see the horizontal bar can be drag to IV column directly), so the returned value of this method is 255.

If you want to get the maximum column that has cell data, please use Cells.getMaxDataColumn() instead.