Skip to content
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

222 gridlines on selected sheets #228

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions gptables/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def produce_workbook(
notesheet_label = "Notes",
notesheet_options = {},
auto_width = True,
gridlines = 2,
gridlines = "hide_all",
cover_gridlines = False
):
"""
Expand Down Expand Up @@ -52,9 +52,10 @@ def produce_workbook(
auto_width : bool, optional
indicate if column widths should be automatically determined. True
by default.
gridlines : int, optional
option to hide or show gridlines on worksheets. 0 - don't hide gridlines,
1 - hide printed gridlines only, or 2 - hide screen and printed gridlines.
gridlines : string, optional
option to hide or show gridlines on worksheets. "show_all" - don't
hide gridlines, "hide_printed" - hide printed gridlines only, or
"hide_all" - hide screen and printed gridlines.
cover_gridlines : bool, optional
indication if gridlines should apply to the cover worksheet. False
by default.
Expand All @@ -75,7 +76,7 @@ def produce_workbook(
if cover_gridlines:
ws = wb.add_worksheet(cover.cover_label, gridlines=gridlines)
else:
ws = wb.add_worksheet(cover.cover_label, gridlines=2)
ws = wb.add_worksheet(cover.cover_label, gridlines="hide_all")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the if-else is necessary if we specify a default value in the function definition? Does this work if you just have ws = wb.add_worksheet(cover.cover_label, gridlines=gridlines) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if-else is for when you want gridlines on the workbook but not on the cover sheet specifically.

ws.write_cover(cover)

contentsheet = {}
Expand Down Expand Up @@ -119,7 +120,7 @@ def write_workbook(
notesheet_label = "Notes",
notesheet_options = {},
auto_width = True,
gridlines = 2,
gridlines = "hide_all",
cover_gridlines = False
):

Expand Down Expand Up @@ -162,9 +163,10 @@ def write_workbook(
auto_width : bool, optional
indicate if column widths should be automatically determined. True by
default.
gridlines : int, optional
option to hide or show gridlines on worksheets. 0 - don't hide gridlines,
1 - hide printed gridlines only, or 2 - hide screen and printed gridlines.
gridlines : string, optional
option to hide or show gridlines on worksheets. "show_all" - don't
hide gridlines, "hide_printed" - hide printed gridlines only, or
"hide_all" - hide screen and printed gridlines.
cover_gridlines : bool, optional
indication if gridlines should apply to the cover worksheet. False
by default.
Expand Down
15 changes: 13 additions & 2 deletions gptables/core/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,14 +1052,18 @@ def __init__(self, filename=None, options={}):
# Set default theme
self.set_theme(gptheme)

def add_worksheet(self, name=None, gridlines=2):
def add_worksheet(self, name=None, gridlines="hide_all"):
"""
Overwrite add_worksheet() to create a GPWorksheet object.

Parameters
----------
name : str (optional)
name of the the worksheet to be created
gridlines : string, optional
option to hide or show gridlines on worksheets. "show_all" - don't
hide gridlines, "hide_printed" - hide printed gridlines only, or
"hide_all" - hide screen and printed gridlines.

Returns
-------
Expand All @@ -1069,7 +1073,14 @@ def add_worksheet(self, name=None, gridlines=2):
worksheet = super(GPWorkbook, self).add_worksheet(name, GPWorksheet)
worksheet.theme = self.theme
worksheet._workbook = self # Create reference to wb, for formatting
worksheet.hide_gridlines(gridlines)

worksheet.hide_gridlines({
"show_all": 1,
"hide_printed": 2,
"hide_all": 3
}[gridlines]
)
ldavies99 marked this conversation as resolved.
Show resolved Hide resolved

return worksheet


Expand Down
Binary file modified gptables/test/expected_workbook.xlsx
Binary file not shown.
2 changes: 2 additions & 0 deletions gptables/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def generate_gpworkbook(output_path):
notes_table=notes_table,
notesheet_label="Notes table",
notesheet_options={"title": "Table with notes"},
gridlines="show_all",
cover_gridlines=False
)

return generate_gpworkbook
Expand Down
Loading