Skip to content

Commit

Permalink
Merge branch 'master' into feature/improve-google-sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
mikahanninen committed Mar 14, 2024
2 parents 0a6a628 + d2fb72b commit 506d791
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 18 deletions.
23 changes: 19 additions & 4 deletions docs/source/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@ Latest versions
`Upcoming release <https://github.com/robocorp/rpaframework/projects/3#column-16713994>`_
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- Library **RPA.Cloud.Google** (:pr:`1157`):
`Released <https://pypi.org/project/rpaframework/#history>`_
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

28.4.0 - 14 Mar 2024
--------------------

- 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.
- Add keyword ``Merge range`` for merging cells in a range.
- Add keyword ``Unmerge range`` for unmerging cells in a range.

- Library **RPA.Cloud.Google** (:pr:`1157``, `rpaframework-google`` **9.0.0**):

- Fix problem with method intellisense in Python development environments.
- Add keyword ``Detect Tables`` for detecting table-like structures in spreadsheet's sheets.
- Add keyword ``Get Sheet Formulas`` for getting formulas from a sheet.
- Add keyword ``To A1 notation`` for converting column number to A1 notation.

`Released <https://pypi.org/project/rpaframework/#history>`_
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

28.3.0 - 22 Feb 2024
--------------------

Expand Down
2 changes: 1 addition & 1 deletion packages/main/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rpaframework"
version = "28.3.0"
version = "28.4.0"
description = "A collection of tools and libraries for RPA"
authors = ["RPA Framework <[email protected]>"]
license = "Apache-2.0"
Expand Down
86 changes: 73 additions & 13 deletions packages/main/src/RPA/Excel/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def create_pivot_table(
fields: List[PivotField],
sort_field: PivotField = None,
sort_direction: str = "descending",
data_range: str = None,
data_range: Any = None,
pivot_name: str = "PivotTable1",
collapse_rows: bool = True,
show_grand_total: bool = True,
Expand Down Expand Up @@ -482,9 +482,14 @@ def create_pivot_table(
"""

self.set_active_worksheet(source_worksheet)
excel_range = (
self.worksheet.Range(data_range) if data_range else self.worksheet.UsedRange
)
if data_range:
excel_range = (
self.get_range(data_range)
if isinstance(data_range, str)
else data_range
)
else:
excel_range = self.worksheet.UsedRange

# Grab the pivot table source data
pivot_cache = self.workbook.PivotCaches().Create(
Expand Down Expand Up @@ -558,7 +563,7 @@ def to_sort_direction(sort_direction: str):
def find(
self,
search_string: str,
search_range: str = None,
search_range: Any = None,
max_results: int = None,
search_order: SearchOrder = SearchOrder.ROWS,
match_case: bool = False,
Expand Down Expand Up @@ -612,9 +617,13 @@ def find(
else constants.xlByColumns
)
if search_range:
search_area = self._app.Range(search_range)
search_area = (
self._app.Range(search_range)
if isinstance(search_range, str)
else search_range
)
else:
search_area = self.worksheet.Cells
search_area = self.worksheet.UsedRange # self.worksheet.Cells
found = search_area.Find(
What=search_string, MatchCase=match_case, SearchOrder=search_order
)
Expand All @@ -635,18 +644,22 @@ def find(
found = search_area.FindNext(found)
return results

def create_table(self, table_name: str, table_range: str = None) -> None:
def create_table(self, table_name: str, table_range: Any = None) -> None:
"""Create a table in the current worksheet.
:param table_name: name for the table
:param table_range: source table range, if not given then
the whole used range of `source_worksheet` will be used
"""
excel_range = (
self.worksheet.Range(table_range)
if table_range
else self.worksheet.UsedRange
)
if table_range:
excel_range = (
self.get_range(table_range)
if isinstance(table_range, str)
else table_range
)
else:
excel_range = self.worksheet.UsedRange

self.worksheet.ListObjects.Add(
SourceType=constants.xlSrcRange,
Source=excel_range,
Expand Down Expand Up @@ -823,3 +836,50 @@ def write_data_to_range(
f"Total range column count {range_columns} "
f"is different from data to write column count {row_columns}"
)

def remove_hidden_columns_and_rows(
self, initial_range: Any, worksheet: Any = None
) -> Any:
"""Removes hidden columns and rows from a range and returns a new range.
:param initial_range: range of cells to remove hidden columns and rows from
:param worksheet: set active worksheet before removing hidden columns and rows
:return: new range or initial range if no hidden cells found
"""
initial_range = (
self.get_range(initial_range)
if isinstance(initial_range, str)
else initial_range
)
if worksheet:
self.set_active_worksheet(worksheet)
try:
visible_range = initial_range.SpecialCells(constants.xlCellTypeVisible)
return visible_range
except Exception as e: # pylint: disable=broad-except
self.logger.error(f"No visible cells found or an error occurred:f{str(e)}")
return initial_range

def unmerge_range(self, initial_range: Any) -> None:
"""Unmerges a range of cells.
:param initial_range: range of cells to unmerge
"""
initial_range = (
self.get_range(initial_range)
if isinstance(initial_range, str)
else initial_range
)
initial_range.UnMerge()

def merge_range(self, initial_range: Any) -> None:
"""Merges a range of cells.
:param initial_range: range of cells to merge
"""
initial_range = (
self.get_range(initial_range)
if isinstance(initial_range, str)
else initial_range
)
initial_range.Merge()
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 506d791

Please sign in to comment.