-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for specifing sheet from Excel file to be converted
- Loading branch information
1 parent
66c8a52
commit 64fc4f1
Showing
4 changed files
with
68 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
from typing import Any, List, Tuple | ||
from typing import Any, List, Optional, Tuple, cast | ||
|
||
from openpyxl import load_workbook | ||
from openpyxl.worksheet.worksheet import Worksheet | ||
|
||
ListOfTuples = List[Tuple[Any, ...]] | ||
|
||
|
||
def _get_sheet_content(path_to_file: str) -> ListOfTuples: | ||
wb = load_workbook(filename=path_to_file) | ||
sheet = wb.active | ||
def get_list_of_tuples_from_excel( | ||
path_to_file: str, sheet_name: Optional[str] = None | ||
) -> List[Tuple[Any, ...]]: | ||
workbook = load_workbook(filename=path_to_file) | ||
if sheet_name: | ||
sheet = cast(Worksheet, workbook[sheet_name]) | ||
else: | ||
sheet = workbook.active | ||
|
||
return list(sheet.values) | ||
|
||
|
||
def get_list_of_tuples_from_excel(path_to_file: str) -> ListOfTuples: | ||
return _get_sheet_content(path_to_file) |
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
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