Метод Position.compare
Метод сравнивает заданную позицию с текущей.
Вызов
public int? compare(Position other)
Параметры
other:позиция для сравнения с текущей, тип Position.
Возвращает
- положительное расстояние, если текущая позиция больше заданной.
- отрицательное расстояние, если текущая позиция меньше заданной.
- 0, если позиции равны.
null, если позиции нельзя сравнить (позиции в разных документах, в тексте и в колонтитуле и т.д.).
Примеры для текстового документа
Table table1 = document.getRange().getBegin().insertTable(2, 2, "table1");
Position positionDoc = document.getRange().getBegin();
Position positionTable = table1.getRange().getBegin();
Position positionCell = table1.getCell(new CellPosition(0, 0)).getRange().getBegin();
if (positionDoc.compare(positionTable) + positionTable.compare(positionCell) == 0)
{
document.getRange().getBegin().insertText("Some text");
Position positionBegin = document.getRange().getBegin();
Position positionEnd = document.getRange().getEnd();
Console.WriteLine(positionBegin.compare(positionEnd)); // -10
Console.WriteLine(positionEnd.compare(positionBegin)); // 10
}
Пример для табличного документа
Table sheet = document.getBlocks().getTable(0);
Position firstCellEnd = sheet.getCell("A1").getRange().getEnd();
Position secondCellBegin = sheet.getCell("B1").getRange().getBegin();
Console.WriteLine(firstCellEnd.compare(secondCellBegin)); // 0