Перечисление TextUnit
В таблице представлены варианты разделения текста на диапазоны. Используется в методах Position.getCurrentRange(), Position.getNextRange() и Position.getPreviousRange().
| Значение | Описание |
|---|---|
TextUnit_Character | Разделение по символам |
TextUnit_Word | Разделение по словам (символы-разделители считаются отдельными словами) |
TextUnit_Sentence | Разделение по предложениям (разделители после предложения считаются его частью) |
TextUnit_Paragraph | Разделение по абзацам |
Пример
secondSentence = document.getRange().getBegin().getNextRange(myOfficeSDK.TextUnit_Sentence)
firstSentenceLastWord = secondSentence.getBegin().getPreviousRange(myOfficeSDK.TextUnit_Word)
while firstSentenceLastWord.getContentEnd().compare(firstSentenceLastWord.getBegin()) == 1:
firstSentenceLastWord = firstSentenceLastWord.getBegin().getPreviousRange(myOfficeSDK.TextUnit_Word)
thirdSentenceFirstLetter = secondSentence.getContentEnd().getCurrentRange(myOfficeSDK.TextUnit_Character)
print(secondSentence.extractText())
# Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
print(firstSentenceLastWord.extractText())
# aliqua
print(thirdSentenceFirstLetter.extractText())
# D