Skip to content

Commit

Permalink
Improve RPA.Word.Application selection usage (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikahanninen authored Mar 14, 2024
1 parent 92f13c6 commit f910f97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/source/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Latest versions
`Upcoming release <https://github.com/robocorp/rpaframework/projects/3#column-16713994>`_
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- Library **RPA.Word.Application** (:pr:`1159`):

- Add keyword ``Select current paragraph`` for selecting the current paragraph.
- Add keyword ``Select paragraphs`` for selecting previous/next paragraphs.
- Add keyword ``Copy selection to clipboard`` for copying the selection to the clipboard.

- Library **RPA.Excel.Application** (:pr:`1158`):

- Add keyword ``Remove hidden columns and rows`` from given range.
Expand Down
21 changes: 21 additions & 0 deletions packages/main/src/RPA/Word/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,24 @@ def write_text(

self.app.Selection.TypeText(text)
self.app.Selection.Select()

def select_current_paragraph(self):
"""Select text in current active paragraph."""
self.app.Selection.Paragraphs(1).Range.Select()

def copy_selection_to_clipboard(self):
"""Copy current text selection to clipboard."""
self.app.Selection.Copy()

def select_paragraph(self, count: int = 1):
"""Select paragraph(s) from current cursor position.
Negative `count` moves cursor up number of paragraphs and
positive `count` moves cursor down number of paragraphs.
:param count: number of paragraphs to select
"""
start = self.app.Selection.Range.Start
self.app.Selection.MoveDown(Unit=constants.wdParagraph, Count=count)
end = self.app.Selection.Range.End
self.app.Selection.SetRange(start, end)

0 comments on commit f910f97

Please sign in to comment.