Skip to content

Commit 82e6785

Browse files
authored
222 gridlines on selected sheets (#228)
* Add gridlines to all sheets except cover * Add options for user to show or hide gridlines * Make gridlines off by default * Apply suggested changes and add gridlines to expected workbook in test api * Fix numbering on gridlines * Update expected workbook
1 parent a563638 commit 82e6785

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

gptables/core/api.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def produce_workbook(
1616
notesheet_label = "Notes",
1717
notesheet_options = {},
1818
auto_width = True,
19+
gridlines = "hide_all",
20+
cover_gridlines = False
1921
):
2022
"""
2123
Produces a GPWorkbook, ready to be written to the specified `.xlsx` file
@@ -50,6 +52,13 @@ def produce_workbook(
5052
auto_width : bool, optional
5153
indicate if column widths should be automatically determined. True
5254
by default.
55+
gridlines : string, optional
56+
option to hide or show gridlines on worksheets. "show_all" - don't
57+
hide gridlines, "hide_printed" - hide printed gridlines only, or
58+
"hide_all" - hide screen and printed gridlines.
59+
cover_gridlines : bool, optional
60+
indication if gridlines should apply to the cover worksheet. False
61+
by default.
5362
5463
Returns
5564
-------
@@ -64,7 +73,10 @@ def produce_workbook(
6473
wb.set_theme(theme)
6574

6675
if cover is not None:
67-
ws = wb.add_worksheet(cover.cover_label)
76+
if cover_gridlines:
77+
ws = wb.add_worksheet(cover.cover_label, gridlines=gridlines)
78+
else:
79+
ws = wb.add_worksheet(cover.cover_label, gridlines="hide_all")
6880
ws.write_cover(cover)
6981

7082
contentsheet = {}
@@ -90,7 +102,7 @@ def produce_workbook(
90102

91103
sheets = {**contentsheet, **notesheet, **sheets}
92104
for label, gptable in sheets.items():
93-
ws = wb.add_worksheet(label)
105+
ws = wb.add_worksheet(label, gridlines=gridlines)
94106
ws.write_gptable(gptable, auto_width, wb._annotations)
95107

96108
return wb
@@ -108,6 +120,8 @@ def write_workbook(
108120
notesheet_label = "Notes",
109121
notesheet_options = {},
110122
auto_width = True,
123+
gridlines = "hide_all",
124+
cover_gridlines = False
111125
):
112126

113127
"""
@@ -149,6 +163,13 @@ def write_workbook(
149163
auto_width : bool, optional
150164
indicate if column widths should be automatically determined. True by
151165
default.
166+
gridlines : string, optional
167+
option to hide or show gridlines on worksheets. "show_all" - don't
168+
hide gridlines, "hide_printed" - hide printed gridlines only, or
169+
"hide_all" - hide screen and printed gridlines.
170+
cover_gridlines : bool, optional
171+
indication if gridlines should apply to the cover worksheet. False
172+
by default.
152173
contentsheet : str
153174
alias for contentsheet_label, deprecated in v1.1.0
154175
@@ -169,6 +190,8 @@ def write_workbook(
169190
notes_table,
170191
notesheet_label,
171192
notesheet_options,
172-
auto_width
193+
auto_width,
194+
gridlines,
195+
cover_gridlines
173196
)
174197
wb.close()

gptables/core/wrappers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,14 +1052,18 @@ def __init__(self, filename=None, options={}):
10521052
# Set default theme
10531053
self.set_theme(gptheme)
10541054

1055-
def add_worksheet(self, name=None):
1055+
def add_worksheet(self, name=None, gridlines="hide_all"):
10561056
"""
10571057
Overwrite add_worksheet() to create a GPWorksheet object.
10581058
10591059
Parameters
10601060
----------
10611061
name : str (optional)
10621062
name of the the worksheet to be created
1063+
gridlines : string, optional
1064+
option to hide or show gridlines on worksheets. "show_all" - don't
1065+
hide gridlines, "hide_printed" - hide printed gridlines only, or
1066+
"hide_all" - hide screen and printed gridlines.
10631067
10641068
Returns
10651069
-------
@@ -1069,7 +1073,14 @@ def add_worksheet(self, name=None):
10691073
worksheet = super(GPWorkbook, self).add_worksheet(name, GPWorksheet)
10701074
worksheet.theme = self.theme
10711075
worksheet._workbook = self # Create reference to wb, for formatting
1072-
worksheet.hide_gridlines(2)
1076+
1077+
worksheet.hide_gridlines({
1078+
"show_all": 0,
1079+
"hide_printed": 1,
1080+
"hide_all": 2
1081+
}[gridlines]
1082+
)
1083+
10731084
return worksheet
10741085

10751086

gptables/test/expected_workbook.xlsx

15 Bytes
Binary file not shown.

gptables/test/test_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def generate_gpworkbook(output_path):
5858
notes_table=notes_table,
5959
notesheet_label="Notes table",
6060
notesheet_options={"title": "Table with notes"},
61+
gridlines="show_all",
62+
cover_gridlines=False
6163
)
6264

6365
return generate_gpworkbook

0 commit comments

Comments
 (0)