-
Notifications
You must be signed in to change notification settings - Fork 951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_all_worksheet_values feature #1180
Open
swimninja247
wants to merge
8
commits into
burnash:master
Choose a base branch
from
swimninja247:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−2
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
09e46ea
Added column_index_to_letter function with tests
swimninja247 486e4e6
Added extract_title_from_range to utils.py
swimninja247 3428a17
get_all_worksheet_values implemented
swimninja247 09200aa
Format and lint
swimninja247 890c17d
Merge branch 'burnash:master' into master
swimninja247 5e0da11
Made requested changes, linted + formatted
swimninja247 4e7561e
Fixed docstrings formatting
swimninja247 4049286
Fixed a typo
swimninja247 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
URL_KEY_V1_RE = re.compile(r"key=([^&#]+)") | ||
URL_KEY_V2_RE = re.compile(r"/spreadsheets/d/([a-zA-Z0-9-_]+)") | ||
|
||
TITLE_RANGE_RE = re.compile(r"'(.*?)'!.*") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't always work, here we can have 2 cases:
The regex should be improved to match all possible titles. |
||
|
||
Dimension = namedtuple("Dimension", ["rows", "cols"])("ROWS", "COLUMNS") | ||
ValueRenderOption = namedtuple( | ||
"ValueRenderOption", ["formatted", "unformatted", "formula"] | ||
|
@@ -482,6 +484,31 @@ def column_letter_to_index(column): | |
return index | ||
|
||
|
||
def column_index_to_letter(column: int) -> str: | ||
"""Converts a column's numerical index to its letter | ||
|
||
This function is case insensitive | ||
|
||
:param str letter: An int corresponding to the column's numerical index. | ||
Indexed from 1. | ||
:returns: A column label in A1 notation, e.g. 'B'. | ||
Letter case is ignored. | ||
:rtype: int | ||
|
||
Raises :exc:`gspread.exceptions.InvalidInputValue` in case of invalid input. | ||
|
||
Example: | ||
|
||
>>> a1_to_rowcol(1) | ||
'A' | ||
""" | ||
|
||
if not isinstance(column, int) or column < 1: | ||
raise InvalidInputValue(f"invalid value: {column}, must be an int >= 1") | ||
|
||
return rowcol_to_a1(1, column).strip("1") | ||
|
||
|
||
swimninja247 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def cast_to_a1_notation(method): | ||
"""Decorator function casts wrapped arguments to A1 notation in range | ||
method calls. | ||
|
@@ -519,6 +546,27 @@ def extract_id_from_url(url): | |
raise NoValidUrlKeyFound | ||
|
||
|
||
def extract_title_from_range(range_string: str) -> str: | ||
"""Will extract the sheet title from a range. | ||
|
||
:param str letter: A range string | ||
:returns: the title of the worksheet from the range string | ||
:rtype: str | ||
|
||
Raises :exc: `gspread.exceptions.InvalidInputValue` | ||
|
||
Example: | ||
|
||
>>> extract_title_from_range("'Volunteer Portal'!A1:Z1005" -> "Volunteer Portal") | ||
'Volunteer Portal' | ||
""" | ||
match = TITLE_RANGE_RE.search(range_string) | ||
if match: | ||
return match.group(1) | ||
|
||
raise InvalidInputValue | ||
|
||
|
||
def wid_to_gid(wid): | ||
"""Calculate gid of a worksheet from its wid.""" | ||
widval = wid[1:] if len(wid) > 3 else wid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you set it to
[]
empty list when it's not set, then just set the default value to[]
in the argument in the method definition.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the initial solution was right, because usage of a mutable object as default argument can follow wrong behaviour. You can see example of such problem there