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

219 improve formatting options documentation #238

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ env/
*.pyc
*~lock*
docs/build/**
gptables/examples/*.xlsx
gptables/examples/*.xlsx
.vscode/
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"gptables"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
173 changes: 173 additions & 0 deletions docs/source/doc.gptable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,179 @@ This ``additional_formatting`` parameter is best demonstrated by example:
}
]

Formatting methods
ldavies99 marked this conversation as resolved.
Show resolved Hide resolved
^^^^^

The following tables show the Excel format categories, along with an example demonstrating the syntax required
for use in gptables. Some formatting methods use indexing to map to Excel's built-in formats. This information
can be found in the applicable sections below.

^^^^
Font formatting
^^^^

This table demonstrates the font formatting methods available. You can find all options
for `underline styles in the XlsxWriter documentation`_.

.. _`underline styles in the XlsxWriter documentation`: https://xlsxwriter.readthedocs.io/format.html#format-set-underline

.. list-table::
:header-rows: 1
:widths: 19 30
:align: left

* - Description
- Example usage
* - Font type
- {"font_name": "Arial"}
* - Font size
- {"font_size": 30}
* - Font colour
- {"font_color": "red"}
* - Bold
- {"bold": True}
* - Italic
- {"italic": True}
* - Underline
- {"underline": 1}
* - Strikeout
- {"font_strikeout": True}
* - Super/Subscript
- | {"font_script": 1} # Superscript
| {"font_script": 2} # Subscript
..
^^^^^^
Number formatting
^^^^^^

This table demonstrates how to set the numeric format using indexing and string arguments. You can find all
options for `numeric formats in the XlsxWriter documentation`_.

.. _`numeric formats in the XlsxWriter documentation`: https://xlsxwriter.readthedocs.io/format.html#format-set-num-format

.. list-table::
:header-rows: 1
:widths: 19 30
:align: left

* - Description
- Example usage
* - Numeric format
- | {"num_format": 1} # Format index
| {"num_format": "d mmm yyyy"} # Format string
..

^^^^^^^^^^^
Protection formatting
^^^^^^^^^^^

This table demonstrates the protection methods available.

.. list-table::
:header-rows: 1
:widths: 19 30
:align: left

* - Description
- Example usage
* - Lock cells
- {"locked": True}
* - Hide formulas
- {"hidden": True}
..

^^^^^^^^^^^^
Alignment formatting
^^^^^^^^^^^^

This table demonstrates the alignment formatting options available. You can find all options for
`horizontal and vertical alignment in the XlsxWriter documentation`_.

.. _`horizontal and vertical alignment in the XlsxWriter documentation`: https://xlsxwriter.readthedocs.io/format.html#format-set-align

.. list-table::
:header-rows: 1
:widths: 19 30
:align: left

* - Description
- Example usage
* - Horizontal align
- {"align": "center"}
* - Vertical align
- {"align": "vcenter"}
* - Rotation
- {"rotation": 30}
* - Text wrap
- {"text_wrap": True}
* - Center across
- {"set_center_across": True}
* - Indentation
- {"indentation":2}
* - Shrink to fit
- {"shrink": True}
..

^^^^^^^^^^^^^^^^
Pattern formatting
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is pattern formatting?

^^^^^^^^^^^^^^^^

This table demonstrates the pattern formatting options available.

.. list-table::
:header-rows: 1
:widths: 19 30
:align: left

* - Description
- Example usage
* - Cell pattern
- {"pattern": 1}
* - Background colour
- {"bg_color": "white"}
* - Foreground colour
- {"fg_color": "white"}
..

^^^^^^^^^^^^^^^^^^
Border formatting
^^^^^^^^^^^^^^^^^^

This table demonstrates the border formatting options available. You can find all options
for `border styles in the XlsxWriter documentation`_.

.. _`border styles in the XlsxWriter documentation`: https://xlsxwriter.readthedocs.io/format.html#format-set-border

.. list-table::
:header-rows: 1
:widths: 19 30
:align: left

* - Description
- Example usage
* - Cell border
- {"border": 1}
* - Bottom border
- {"bottom": 1}
* - Top border
- {"top": 1}
* - Left border
- {"left": 1}
* - Right border
- {"right": 1}
* - Border colour
- {"border_color": "red"}
* - Bottom colour
- {"bottom_color":"#FF0000"}
* - Top colour
- {"top_color": "red"}
* - Left colour
- {"left_color": "#FF0000"}
* - Right colour
- {"right_color": "red"}

..

For any formatting beyond this, if the package should support it then please raise an issue
or create a pull request. Otherwise, you will need to modify the underlying
:class:`~.core.wrappers.GPWorkbook` or :class:`~.core.wrappers.GPWorksheet` objects
Expand Down
9 changes: 4 additions & 5 deletions gptables/examples/penguins_additional_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from pathlib import Path

## Read data and arrange
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down Expand Up @@ -61,7 +61,7 @@
{
"row": {
"rows": -1, # Numbers only, but can refer to last row using -1
"format": {"bottom": 1, "indentation":2}, # Give the last row a border at the bottom of each cell and indents two levels
"format": {"bottom": 1, "indent":2}, # Give the last row a border at the bottom of each cell and indents two levels
}
},
]
Expand Down Expand Up @@ -102,5 +102,4 @@

wb.close()
print("Output written at: ", output_path)



4 changes: 2 additions & 2 deletions gptables/examples/penguins_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from pathlib import Path

## Read data
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down
4 changes: 2 additions & 2 deletions gptables/examples/penguins_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from pathlib import Path

## Read data
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down
4 changes: 2 additions & 2 deletions gptables/examples/penguins_minimal_alternate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from pathlib import Path

## Read data
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down
4 changes: 2 additions & 2 deletions gptables/examples/penguins_multiple_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from copy import deepcopy

## Read data
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down
4 changes: 2 additions & 2 deletions gptables/examples/penguins_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from pathlib import Path

## Read data
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down
4 changes: 2 additions & 2 deletions gptables/examples/penguins_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from pathlib import Path

## Read data
parent_dir = Path(__file__).parent
parent_dir = Path(__file__).parents[1]

penguins_data = pd.read_csv(parent_dir / "penguins.csv")
penguins_data = pd.read_csv(parent_dir / "test/data/penguins.csv")

#Any data processing could go here as long as you end with a Pandas dataframe that you want to write in a spreadsheet

Expand Down
Loading
Loading