-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Allow safe access to .book
in ExcelWriter
#45687
Changes from 6 commits
a641cce
ba7ff35
8f433f0
fdef619
7ede1a8
61c92c2
bda2efc
d8415bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,11 @@ def __init__( | |
|
||
self.book = Workbook(self.handles.handle, **engine_kwargs) | ||
|
||
@property | ||
def sheets(self) -> dict[str, Any]: | ||
result = self.book.sheetnames | ||
return result | ||
|
||
def save(self) -> None: | ||
""" | ||
Save workbook to disk. | ||
|
@@ -222,11 +227,9 @@ def write_cells( | |
# Write the frame cells using xlsxwriter. | ||
sheet_name = self._get_sheet_name(sheet_name) | ||
|
||
if sheet_name in self.sheets: | ||
wks = self.sheets[sheet_name] | ||
else: | ||
wks = self.book.get_worksheet_by_name(sheet_name) | ||
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. i would change 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. Would the property be something besides just |
||
if wks is None: | ||
wks = self.book.add_worksheet(sheet_name) | ||
self.sheets[sheet_name] = wks | ||
|
||
style_dict = {"null": None} | ||
|
||
|
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.
is there a way to type these more specifically?
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.
Not easily, as far as I can tell. I plan to look into this more in the future.
Regarding whatsnew - this is not user facing. Currently in docs no attribute of ExcelWriter is public. I'd like to refactor ExcelWriter (namely, making protected attributes start with
_
) before updating docs.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.
got it totally fine (make issues if you cannot to get to it soon), otherwise PR's totally fine.
can we use the base class generic for typing? (again nbd)