Skip to content

Commit

Permalink
Merge pull request #587 from ryfi/staging
Browse files Browse the repository at this point in the history
Added ability to sync hyperlink value at the cell level.
  • Loading branch information
nithinmurali authored Sep 28, 2023
2 parents 316d216 + ed3b6d6 commit 862cb9b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pygsheets/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, pos, val='', worksheet=None, cell_data=None):
self._value = val # formatted value
self._unformated_value = val # un-formatted value
self._formula = ''
self._hyperlink = ''
self._note = None
if self._worksheet is None:
self._linked = False
Expand Down Expand Up @@ -141,6 +142,18 @@ def formula(self, formula):
self.parse_value = tmp
self.fetch()

@property
def hyperlink(self):
"""Get this cell's hyperlink if any."""
return self._hyperlink

@hyperlink.setter
def hyperlink(self, hyperlink):
if self._simplecell:
self.fetch()
self._hyperlink = hyperlink
self.update()

@property
def horizontal_alignment(self):
"""Horizontal alignment of the value in this cell.
Expand Down Expand Up @@ -500,6 +513,9 @@ def get_json(self):
fg = ret_json["userEnteredFormat"]["textFormat"].get('foregroundColor', None)
ret_json["userEnteredFormat"]["textFormat"]['foregroundColor'] = format_color(fg, to='dict')

if self._hyperlink != '':
ret_json["userEnteredFormat"]["textFormat"]['link'] = {'uri': self._hyperlink}

if self.borders is not None:
ret_json["userEnteredFormat"]["borders"] = self.borders
if self._horizontal_alignment is not None:
Expand Down Expand Up @@ -553,7 +569,7 @@ def set_json(self, cell_data):
self._vertical_alignment = \
VerticalAlignment[nvertical_alignment] if nvertical_alignment is not None else None

self.hyperlink = cell_data.get('hyperlink', '')
self._hyperlink = cell_data.get('hyperlink', '')

def __setattr__(self, key, value):
if key not in ['_linked', '_worksheet']:
Expand Down

0 comments on commit 862cb9b

Please sign in to comment.