int endRowIndex = textTableCellReferences[i].getEndRowIndex();
IETextTableCell startCell = textTable.getCell(startRowIndex,startColumnIndex);
IETextTableCell endCell = textTable.getCell(endRowIndex,endColumnIndex);
String formula = "";
TextTableCellReference textTableCellReference = null;
int startTableIndex = textTable.getTextTableIndex(startCell.getTableCell().getTextTable());
int endTableIndex = textTable.getTextTableIndex(endCell.getTableCell().getTextTable());
ITextTable table = textTable.getTextTable(startTableIndex);
if(!startCell.getName().getName().equals(endCell.getName().getName())) {
if(startTableIndex != endTableIndex) {
formula = table.getName()+ "." + startCell.getTableCell().getName().getName() + ":" + table.getCell(endColumnIndex,table.getRowCount()-1).getName().getName();
textTableCellReference = new TextTableCellReference(formula);
newTextTableCellReferences.add(textTableCellReference);
for(int j = startTableIndex+1; j < endTableIndex; j++) {
table = textTable.getTextTable(j);
formula = table.getName()+"." +TextTableCellNameHelper.getColumnCharacter(startCell.getName().getColumnIndex()) + "1" + ":" + table.getCell(endColumnIndex,table.getRowCount()-1).getName().getName();
textTableCellReference = new TextTableCellReference(formula);
newTextTableCellReferences.add(textTableCellReference);
}
table = textTable.getTextTable(endTableIndex);
formula = table.getName()+"." + TextTableCellNameHelper.getColumnCharacter(startCell.getName().getColumnIndex()) + "1" + ":" + endCell.getTableCell().getName().getName();
}
else {
formula = table.getName()+"." + startCell.getTableCell().getName().getName() + ":" + endCell.getTableCell().getName().getName();
}
}
else {
formula = table.getName() + "." + startCell.getTableCell().getName().getName();
}
textTableCellReference = new TextTableCellReference(formula);
newTextTableCellReferences.add(textTableCellReference);
TextTableCellReference[] references = new TextTableCellReference[newTextTableCellReferences.size()];
references = (TextTableCellReference[])newTextTableCellReferences.toArray(references);
textTableFormulaModel.replaceCellReference(textTableCellReferences[i],references);