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

Enchance style's docstring and update the old docstring #174

Merged
merged 2 commits into from
Dec 15, 2024
Merged
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
7 changes: 1 addition & 6 deletions pyfastexcel/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ class ExcelDriver:
_FILE_PROPS (dict[str, str]): Default file properties for the Excel
file.
_PROTECT_ALGORITHM (tuple[str]): Algorithm for the workbook protection

### Methods:
__init__(): Initializes the ExcelDriver.
_read_lib(lib_path: str): Reads a library for Excel manipulation.
read_lib_and_create_excel(lib_path: str = None): Reads the library and
creates the Excel file.
"""

_FILE_PROPS = {
Expand Down Expand Up @@ -143,6 +137,7 @@ def read_lib_and_create_excel(

Args:
lib_path (str, optional): The path to the library. Defaults to None.
ignore_go_panic (bool): The flag to determine should trigger panic in go.

Returns:
bytes: The byte data of the created Excel file.
Expand Down
59 changes: 39 additions & 20 deletions pyfastexcel/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@

class Font(BaseModel):
"""
Defines font settings for text elements in a chart.

Attributes:
bold (Optional[bool]): Specifies if the text is bold.
color (Optional[str]): The color of the text.
family (Optional[str]): The font family for the text.
italic (Optional[bool]): Specifies if the text is italic.
size (Optional[float]): The font size for the text.
strike (Optional[bool]): Specifies if the text has a strikethrough.
underline (Optional[str]): The style of underline for the text.
vert_align (Optional[str]): Vertical alignment for the text, such as
"baseline", "superscript" or "subscript".
Model representing a Font style in Excel.
"""

bold: Optional[bool] = Field(False, serialization_alias='Bold')
Expand All @@ -41,14 +30,7 @@ class Font(BaseModel):

class Fill(BaseModel):
"""
Describes the fill settings.

Attributes:
ftype (Optional[Literal['pattern', 'gradient']]): The type of fill, either
'pattern' or 'gradient'.
pattern (Optional[int]): The pattern index for fill (between 0 and 18).
color (Optional[str]): The fill color (Only support hex color value).
shading (Optional[int]): The shading index for the fill (between 0 and 5).
Model representing a Fill style in Excel.
"""

# fgColor is the backward compatibility for openpyxl_style_writer, it is the same as 'color'
Expand Down Expand Up @@ -116,6 +98,10 @@ class Protection(BaseModel):


class DefaultStyle:
"""
Module for defining and customizing default and custom styles for formatting purposes.
"""

# params
font_params: ClassVar[Optional[dict[str, Any]]] = None
fill_params: ClassVar[Optional[dict[str, Any]]] = None
Expand Down Expand Up @@ -281,6 +267,28 @@ def __repr__(self) -> str:

class CustomStyle(DefaultStyle):
def __init__(self, **kwargs):
"""
Initialize a CustomStyle instance with optional custom styling attributes.

Args:
- font_params (dict): Advanced customization for font settings.
- fill_params (dict): Advanced customization for fill settings.
- ali_params (dict): Advanced customization for alignment settings.
- border_params (dict): Advanced customization for border settings.
- number_format (str): Custom number format.
- protect (bool): Whether the cells are locked.
- hidden (bool): Whether the cells are hidden.
- font_name (str): Font name.
- font_color (str): Font color in hex format (e.g., 'FF0000').
- font_size (int): Font size.
- font_bold (bool): Whether the font is bold.
- fill_color (str): Fill color in hex format.
- ali_horizontal (str): Horizontal alignment (e.g., 'center').
- ali_vertical (str): Vertical alignment (e.g., 'top').
- ali_wrap_text (bool): Whether text wrapping is enabled.
- border_style_* (str): Border styles for top, right, left, and bottom.
- border_color_* (str): Border colors for top, right, left, and bottom.
"""
super().__init__()
self.set_custom_style(**kwargs)

Expand Down Expand Up @@ -358,6 +366,17 @@ def _apply_settings(self):
)

def clone_and_modify(self, **kwargs):
"""
Create a deep copy of the current CustomStyle instance and modify it with
the provided attributes.

Args:
**kwargs: Keyword arguments for the style customization.
(Refer to `__init__` for supported parameters.)

Returns:
CustomStyle: A new CustomStyle instance with the modified attributes.
"""
cloned_style = copy.deepcopy(self)
cloned_style.set_custom_style(**kwargs)
return cloned_style
11 changes: 0 additions & 11 deletions pyfastexcel/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@
class StreamWriter(Workbook):
"""
A class for writing data to Excel files with or without custom styles.

Attributes:
_row_list (list[Tuple[str, str | CustomStyle]]): A list of tuples
representing rows with values and styles.
data (list[dict[str, str]]): The data to be written to the Excel file.

Methods:
__init__(data: list[dict[str, str]]): Initializes the StreamWriter.
row_append(value: str, style: str | CustomStyle): Appends a value to
the row list.
create_row(is_header: bool = False): Creates a row in the Excel data.
"""

def __init__(self, data: Optional[list[dict[str, str]]] = None):
Expand Down
Loading