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 5 commits
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
29 changes: 26 additions & 3 deletions gptables/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def produce_workbook(
notesheet_label = "Notes",
notesheet_options = {},
auto_width = True,
gridlines = "hide_all",
cover_gridlines = False
):
"""
Produces a GPWorkbook, ready to be written to the specified `.xlsx` file
Expand Down Expand Up @@ -50,6 +52,13 @@ def produce_workbook(
auto_width : bool, optional
indicate if column widths should be automatically determined. True
by default.
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.

Returns
-------
Expand All @@ -64,7 +73,10 @@ def produce_workbook(
wb.set_theme(theme)

if cover is not None:
ws = wb.add_worksheet(cover.cover_label)
if cover_gridlines:
ws = wb.add_worksheet(cover.cover_label, gridlines=gridlines)
else:
ws = wb.add_worksheet(cover.cover_label, gridlines="hide_all")
ws.write_cover(cover)

contentsheet = {}
Expand All @@ -90,7 +102,7 @@ def produce_workbook(

sheets = {**contentsheet, **notesheet, **sheets}
for label, gptable in sheets.items():
ws = wb.add_worksheet(label)
ws = wb.add_worksheet(label, gridlines=gridlines)
ws.write_gptable(gptable, auto_width, wb._annotations)

return wb
Expand All @@ -108,6 +120,8 @@ def write_workbook(
notesheet_label = "Notes",
notesheet_options = {},
auto_width = True,
gridlines = "hide_all",
cover_gridlines = False
):

"""
Expand Down Expand Up @@ -149,6 +163,13 @@ def write_workbook(
auto_width : bool, optional
indicate if column widths should be automatically determined. True by
default.
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.
contentsheet : str
alias for contentsheet_label, deprecated in v1.1.0

Expand All @@ -169,6 +190,8 @@ def write_workbook(
notes_table,
notesheet_label,
notesheet_options,
auto_width
auto_width,
gridlines,
cover_gridlines
)
wb.close()
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):
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):
worksheet = super(GPWorkbook, self).add_worksheet(name, GPWorksheet)
worksheet.theme = self.theme
worksheet._workbook = self # Create reference to wb, for formatting
worksheet.hide_gridlines(2)

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