-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[openpyxl] Annotate Worksheet and other items #9892
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cb406fc
[openpyxl] Annotate Worksheet and other items
srittau 71463c4
Fix Worksheet.rows and .values
srittau 0fbfe41
Add openpyxl.cell.rich_text
srittau 9f05e4e
Add all possible cell types
srittau d174029
Apply feedback from review
srittau f972378
Fix CI errors
srittau 2afbf1d
Change _HasStr to a type alias
srittau 9b414d3
Fix import, typo
srittau abe3071
Update stubs/openpyxl/openpyxl/cell/rich_text.pyi
srittau ec4efe4
Fix CI
AlexWaygood 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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from collections.abc import Iterable | ||
from typing import overload | ||
from typing_extensions import Self | ||
|
||
from openpyxl.descriptors import Strict, String, Typed | ||
|
||
class TextBlock(Strict): | ||
font: Typed | ||
text: String | ||
|
||
def __init__(self, font: Typed, text: String) -> None: ... | ||
def __eq__(self, other: TextBlock) -> bool: ... # type: ignore[override] | ||
|
||
class CellRichText(list[str | TextBlock]): | ||
@overload | ||
def __init__(self, __args: list[str] | list[TextBlock] | list[str | TextBlock] | tuple[str | TextBlock, ...]) -> None: ... | ||
@overload | ||
def __init__(self, *args: str | TextBlock) -> None: ... | ||
@classmethod | ||
def from_tree(cls, node) -> Self: ... | ||
def __add__(self, arg: Iterable[str | TextBlock]) -> CellRichText: ... # type: ignore[override] | ||
def append(self, arg: str | TextBlock) -> None: ... | ||
def extend(self, arg: Iterable[str | TextBlock]) -> None: ... | ||
def as_list(self) -> list[str]: ... |
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,7 +1,9 @@ | ||
from _typeshed import Incomplete | ||
from collections import defaultdict | ||
from typing import TypeVar | ||
|
||
class BoundDictionary(defaultdict[Incomplete, Incomplete]): | ||
reference: Incomplete | ||
def __init__(self, reference: Incomplete | None = ..., *args, **kw) -> None: ... | ||
def __getitem__(self, key): ... | ||
_KT = TypeVar("_KT") | ||
_VT = TypeVar("_VT") | ||
|
||
class BoundDictionary(defaultdict[_KT, _VT]): | ||
reference: str | None | ||
def __init__(self, reference: str | None = None, *args, **kw) -> None: ... | ||
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 |
---|---|---|
@@ -1,25 +1,34 @@ | ||
from _typeshed import Incomplete | ||
from collections.abc import Generator, Iterable, Iterator | ||
from datetime import datetime | ||
from typing import overload | ||
from typing_extensions import Literal | ||
from typing import Any, overload | ||
from typing_extensions import Final, Literal | ||
|
||
from openpyxl.cell.cell import Cell | ||
from openpyxl.cell.cell import Cell, _CellValue | ||
from openpyxl.formatting.formatting import ConditionalFormattingList | ||
from openpyxl.workbook.child import _WorkbookChild | ||
from openpyxl.workbook.defined_name import DefinedNameDict | ||
from openpyxl.workbook.workbook import Workbook | ||
from openpyxl.worksheet.cell_range import CellRange | ||
from openpyxl.worksheet.datavalidation import DataValidation | ||
from openpyxl.worksheet.cell_range import CellRange, MultiCellRange | ||
from openpyxl.worksheet.datavalidation import DataValidation, DataValidationList | ||
from openpyxl.worksheet.dimensions import ColumnDimension, DimensionHolder, RowDimension, SheetFormatProperties | ||
from openpyxl.worksheet.filters import AutoFilter | ||
from openpyxl.worksheet.page import PageMargins, PrintOptions, PrintPageSetup | ||
from openpyxl.worksheet.pagebreak import ColBreak, RowBreak | ||
from openpyxl.worksheet.properties import WorksheetProperties | ||
from openpyxl.worksheet.protection import SheetProtection | ||
from openpyxl.worksheet.scenario import ScenarioList | ||
from openpyxl.worksheet.table import Table, TableList | ||
from openpyxl.worksheet.views import SheetView | ||
from openpyxl.worksheet.views import SheetView, SheetViewList | ||
|
||
class Worksheet(_WorkbookChild): | ||
mime_type: str | ||
BREAK_NONE: int | ||
BREAK_ROW: int | ||
BREAK_COLUMN: int | ||
SHEETSTATE_VISIBLE: str | ||
SHEETSTATE_HIDDEN: str | ||
SHEETSTATE_VERYHIDDEN: str | ||
SHEETSTATE_VISIBLE: Final = "visible" | ||
SHEETSTATE_HIDDEN: Final = "hidden" | ||
SHEETSTATE_VERYHIDDEN: Final = "veryHidden" | ||
PAPERSIZE_LETTER: str | ||
PAPERSIZE_LETTER_SMALL: str | ||
PAPERSIZE_TABLOID: str | ||
|
@@ -33,6 +42,27 @@ class Worksheet(_WorkbookChild): | |
PAPERSIZE_A5: str | ||
ORIENTATION_PORTRAIT: str | ||
ORIENTATION_LANDSCAPE: str | ||
|
||
row_dimensions: DimensionHolder[RowDimension] | ||
column_dimensions: DimensionHolder[ColumnDimension] | ||
row_breaks: RowBreak | ||
col_breaks: ColBreak | ||
merged_cells: MultiCellRange | ||
data_validations: DataValidationList | ||
sheet_state: Literal["visible", "hidden", "veryHidden"] | ||
page_setup: PrintPageSetup | ||
print_options: PrintOptions | ||
page_margins: PageMargins | ||
views: SheetViewList | ||
protection: SheetProtection | ||
defined_names: DefinedNameDict | ||
auto_filter: AutoFilter | ||
conditional_formatting: ConditionalFormattingList | ||
legacy_drawing: Incomplete | None | ||
sheet_properties: WorksheetProperties | ||
sheet_format: SheetFormatProperties | ||
scenarios: ScenarioList | ||
|
||
def __init__(self, parent: Workbook, title: str | None = ...) -> None: ... | ||
@property | ||
def sheet_view(self) -> SheetView: ... | ||
|
@@ -49,7 +79,10 @@ class Worksheet(_WorkbookChild): | |
@freeze_panes.setter | ||
def freeze_panes(self, topLeftCell: Incomplete | None = ...) -> None: ... | ||
def cell(self, row: int, column: int, value: str | None = ...) -> Cell: ... | ||
def __getitem__(self, key: str | int | slice) -> Cell | tuple[Cell, ...]: ... | ||
@overload | ||
def __getitem__(self, key: int | slice) -> tuple[Cell, ...]: ... | ||
@overload | ||
def __getitem__(self, key: str) -> Any: ... # Cell | tuple[Cell, ...] | ||
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. Another instance where python/typing#566 would come in handy. |
||
def __setitem__(self, key: str, value: str) -> None: ... | ||
def __iter__(self) -> Iterator[Cell]: ... | ||
def __delitem__(self, key: str) -> None: ... | ||
|
@@ -102,9 +135,9 @@ class Worksheet(_WorkbookChild): | |
values_only: bool, | ||
) -> Generator[tuple[Cell | str | float | datetime | None, ...], None, None]: ... | ||
@property | ||
def rows(self) -> Generator[Cell, None, None]: ... | ||
def rows(self) -> Generator[tuple[Cell, ...], None, None]: ... | ||
@property | ||
def values(self) -> Generator[str | float | datetime | None, None, None]: ... | ||
def values(self) -> Generator[tuple[_CellValue, ...], None, None]: ... | ||
@overload | ||
def iter_cols( | ||
self, min_col: int | None, max_col: int | None, min_row: int | None, max_row: int | None, values_only: Literal[True] | ||
|
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.
The
*args, **kwargs
here just forward on the arguments todefaultdict.__init__
, but we have 8 overloads for that. So I'm fine with keeping this as it is for now.