Free Support Forum - aspose.com

GetMaxColumn() gives wrong result

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

workbook.getWorksheets().getActiveSheet().getCells().getMaxColumn()

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?

Hi,

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.

Java


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


Workbook workbook = new Workbook();

workbook.open(path);


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


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

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


System.out.println(col1);

System.out.println(col2);

Hi,

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.