Skip to main content

Метод Position.compare

Метод сравнивает заданную позицию с текущей.

Вызов​


int compare(other)

Параметры​

  • other: позиция для сравнения с текущей, тип Position.

Возвращает​

  • положительное расстояние, если текущая позиция больше заданной.
  • отрицательное расстояние, если текущая позиция меньше заданной.
  • 0, если позиции равны.
  • None, если позиции нельзя сравнить (позиции в разных документах, в тексте и в колонтитуле и т.д.).

Примеры для текстового документа​


table1 = document.getRange().getBegin().insertTable(2, 2, "table1")
positionDoc = document.getRange().getBegin()
positionTable = table1.getRange().getBegin()
positionCell = table1.getCell(myOfficeSDK.CellPosition(0, 0)).getRange().getBegin()

if positionDoc.compare(positionTable) + positionTable.compare(positionCell) == 0:
# True
document.getRange().getBegin().insertText("Some text")
positionBegin = document.getRange().getBegin()
positionEnd = document.getRange().getEnd()

print(positionBegin.compare(positionEnd)) # -10
print(positionEnd.compare(positionBegin)) # 10

Пример для табличного документа​


sheet = document.getBlocks().getTable(0)

firstCellEnd = sheet.getCell("A1").getRange().getEnd()
secondCellBegin = sheet.getCell("B1").getRange().getBegin()

print(firstCellEnd.compare(secondCellBegin)) # 0