Free Support Forum - aspose.com

Getcell () out of bounds error occuring when correct coords are passed

The following code causes an out of bounds exception on the third colmn of the last row. I create a table wth 3 columns and 2 rows and then procede to merge each row into 1 column. When I attempt to retrieve cell 2,1 the exception occurs. If I add another column the error still occurs on the third cell of the last row, similarly if i add more rows the same thing happens. I presume there is some problem with me merging all the cells in the previous rows but I cannot see it and the passed coords are the correct ones assuming that the cell retians its original coords despite merging of previous cells.

Java code

Table addTable = slide.getShapes().addtable(0, 0, slide.getBackground().getWidth(), 0, 3, 2, 2, color.Black );

for ( row = 0; row < 2; row++ ){

Cell cell = addtable.getCell ( 0 , row );

for ( col = 0; col < 2; col++ ){

Cell mergeCell = addTable.getCell (col + 1; row ); // code breaks on this line

addTable.mergeCells( cell, mergeCell );

}

}

Hi,

Please see this post regarding merging.

http://www.aspose.com/community/forums/thread/136181/aspose-slides-merge-cell-property-of-table.aspx

I don't think you understand the question the code works by merging the first and second cell and then merging the resulting cell to the third and last cell of a row. It then proceeds to to this to all the rows. The code below has now been changed to create a table with four rows and three columns. It will merge only the first three rows leaving the last with three columns. This works perfectly and displays correctly however if I change the code to merge the last row as well then the code will give an out of bounds exception when merging the last cell. Why does it work okay for the first three rows and not the last?

Table addTable = slide.getShapes().addtable(0, 0, slide.getBackground().getWidth(), 0, 3, 4, 2, color.Black );

for ( row = 0; row < 3; row++ ){ // change 'row < 3' to 'row < 4' to get the error

Cell cell = addtable.getCell ( 0 , row );

for ( col = 0; col < 2; col++ ){

Cell mergeCell = addTable.getCell (col + 1; row ); // code breaks on this line

addTable.mergeCells( cell, mergeCell );

}

}

It is a special case, we need to handle. Actually, when you finally merge the cells in the last row, column numbers start to decrease and that’s why the exception occurs.

I can't guard against this exception so how long will it be before a new download will be available to address this.

regards

Harry

Hello Harry,

There won’t be any updates for that because it’s correct behavior.
If you change number of columns in a table that is your task to monitor it in the application.

Hello Harry,

For your particular problem, you can create one extra row and delete it later using Table.deleteRow() method.