pyfastexcel 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/PKG-INFO +1 -1
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/__init__.py +2 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/_typing.py +5 -1
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/driver.py +38 -3
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/pyfastexcel.dll +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/pyfastexcel.so +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/style.py +2 -3
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/utils.py +5 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/workbook.py +2 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/worksheet.py +53 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/writer.py +33 -7
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel.egg-info/PKG-INFO +1 -1
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/setup.cfg +1 -1
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/LICENSE +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/README.md +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel/logformatter.py +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel.egg-info/SOURCES.txt +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel.egg-info/dependency_links.txt +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel.egg-info/not-zip-safe +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel.egg-info/requires.txt +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/pyfastexcel.egg-info/top_level.txt +0 -0
- {pyfastexcel-0.1.1 → pyfastexcel-0.1.2}/setup.py +0 -0
|
@@ -2,6 +2,7 @@ from openpyxl_style_writer import CustomStyle, DefaultStyle
|
|
|
2
2
|
|
|
3
3
|
from pyfastexcel.workbook import Workbook
|
|
4
4
|
from pyfastexcel.writer import StreamWriter
|
|
5
|
+
from pyfastexcel.utils import set_debug_level
|
|
5
6
|
|
|
6
7
|
__all__ = [
|
|
7
8
|
'Workbook',
|
|
@@ -10,4 +11,5 @@ __all__ = [
|
|
|
10
11
|
# convinent usage.
|
|
11
12
|
'CustomStyle',
|
|
12
13
|
'DefaultStyle',
|
|
14
|
+
'set_debug_level',
|
|
13
15
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Literal, TypedDict, Optional, List, Union
|
|
3
|
+
from typing import Literal, Protocol, TypedDict, Optional, List, Union
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class CommentTextDict(TypedDict, total=False):
|
|
@@ -21,5 +21,9 @@ class SelectionDict(TypedDict, total=False):
|
|
|
21
21
|
pane: str
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
class Writable(Protocol):
|
|
25
|
+
def write(self, content: str) -> None: ...
|
|
26
|
+
|
|
27
|
+
|
|
24
28
|
CommentTextStructure = Union[str, List[str], CommentTextDict, List[CommentTextDict]]
|
|
25
29
|
SetPanesSelection = List[SelectionDict]
|
|
@@ -2,20 +2,31 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import base64
|
|
4
4
|
import ctypes
|
|
5
|
+
import logging
|
|
5
6
|
import sys
|
|
6
7
|
from datetime import datetime, timezone
|
|
7
8
|
from io import BytesIO
|
|
8
9
|
from pathlib import Path
|
|
10
|
+
from typing import overload
|
|
9
11
|
|
|
10
12
|
import msgspec
|
|
11
13
|
from openpyxl import load_workbook
|
|
12
14
|
from openpyxl_style_writer import CustomStyle
|
|
13
15
|
|
|
16
|
+
from .logformatter import formatter
|
|
14
17
|
from .style import StyleManager
|
|
15
18
|
from .worksheet import WorkSheet
|
|
19
|
+
from ._typing import Writable
|
|
16
20
|
|
|
17
21
|
BASE_DIR = Path(__file__).resolve().parent
|
|
18
22
|
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
style_formatter = logging.StreamHandler()
|
|
25
|
+
style_formatter.setFormatter(formatter)
|
|
26
|
+
|
|
27
|
+
logger.addHandler(style_formatter)
|
|
28
|
+
logger.propagate = False
|
|
29
|
+
|
|
19
30
|
|
|
20
31
|
class ExcelDriver:
|
|
21
32
|
"""
|
|
@@ -87,12 +98,35 @@ class ExcelDriver:
|
|
|
87
98
|
def sheet_list(self):
|
|
88
99
|
return list(self._sheet_list)
|
|
89
100
|
|
|
90
|
-
|
|
101
|
+
@overload
|
|
102
|
+
def save(self, file: Writable) -> None:
|
|
103
|
+
"""
|
|
104
|
+
Saves the workbook to a writable object.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
file (Writable): Writable object that has .write() function.
|
|
108
|
+
"""
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
@overload
|
|
112
|
+
def save(self, path: str) -> None:
|
|
113
|
+
"""
|
|
114
|
+
Saves the workbook to a file.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
path (str): A path to save the file.
|
|
118
|
+
"""
|
|
119
|
+
...
|
|
120
|
+
|
|
121
|
+
def save(self, file_or_path: Writable | str) -> None:
|
|
91
122
|
if not hasattr(self, 'decoded_bytes'):
|
|
92
123
|
self.read_lib_and_create_excel()
|
|
93
124
|
|
|
94
|
-
|
|
95
|
-
|
|
125
|
+
if isinstance(file_or_path, str):
|
|
126
|
+
with open(file_or_path, 'wb') as file:
|
|
127
|
+
file.write(self.decoded_bytes)
|
|
128
|
+
else:
|
|
129
|
+
file_or_path.write(self.decoded_bytes)
|
|
96
130
|
|
|
97
131
|
def __getitem__(self, key: str) -> WorkSheet:
|
|
98
132
|
return self.workbook[key]
|
|
@@ -155,6 +189,7 @@ class ExcelDriver:
|
|
|
155
189
|
# Due to Streaming API of Excelize can't group column currently
|
|
156
190
|
# So implement this function by openpyxl
|
|
157
191
|
if (set_group_columns or set_row_columns) and use_openpyxl is True:
|
|
192
|
+
logger.info('Using openpyxl to group columns and rows...')
|
|
158
193
|
self.decoded_bytes = self._set_group_columns_and_group_rows()
|
|
159
194
|
|
|
160
195
|
return self.decoded_bytes
|
|
Binary file
|
|
Binary file
|
|
@@ -11,11 +11,10 @@ BASE_DIR = Path(__file__).resolve().parent
|
|
|
11
11
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
13
13
|
style_formatter = logging.StreamHandler()
|
|
14
|
-
style_formatter.setLevel(logging.DEBUG)
|
|
15
14
|
style_formatter.setFormatter(formatter)
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
logger.addHandler(style_formatter)
|
|
17
|
+
logger.propagate = False
|
|
19
18
|
|
|
20
19
|
# TODO: Implement a CustomStyle without the dependency of openpyxl_style_writer
|
|
21
20
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import logging
|
|
3
4
|
import re
|
|
4
5
|
import string
|
|
5
6
|
import warnings
|
|
@@ -49,6 +50,10 @@ class Selection:
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
|
|
53
|
+
def set_debug_level(level: int):
|
|
54
|
+
logging.basicConfig(level=level)
|
|
55
|
+
|
|
56
|
+
|
|
52
57
|
def deprecated_warning(msg: str):
|
|
53
58
|
warnings.warn(
|
|
54
59
|
msg,
|
|
@@ -16,6 +16,8 @@ class Workbook(ExcelDriver):
|
|
|
16
16
|
Methods:
|
|
17
17
|
remove_sheet(sheet: str) -> None:
|
|
18
18
|
Removes a sheet from the Excel data.
|
|
19
|
+
rename_sheet(self, old_sheet_name: str, new_sheet_name: str) -> None:
|
|
20
|
+
Rename a sheet.
|
|
19
21
|
create_sheet(sheet_name: str) -> None:
|
|
20
22
|
Creates a new sheet.
|
|
21
23
|
switch_sheet(sheet_name: str) -> None:
|
|
@@ -562,6 +562,27 @@ class WorkSheet(WorkSheetBase):
|
|
|
562
562
|
active_pane: Literal['bottomLeft', 'bottomRight', 'topLeft', 'topRight', ''] = '',
|
|
563
563
|
selection: Optional[SetPanesSelection | list[Selection]] = None,
|
|
564
564
|
) -> None:
|
|
565
|
+
"""
|
|
566
|
+
Sets the panes for the worksheet with options for freezing, splitting, and selection.
|
|
567
|
+
|
|
568
|
+
Args:
|
|
569
|
+
freeze (bool): Whether to freeze the panes.
|
|
570
|
+
split (bool): Whether to split the panes.
|
|
571
|
+
x_split (int): The column position to split or freeze.
|
|
572
|
+
y_split (int): The row position to split or freeze.
|
|
573
|
+
top_left_cell (str): The top-left cell in the split or frozen panes.
|
|
574
|
+
active_pane (Literal['bottomLeft', 'bottomRight', 'topLeft', 'topRight', '']):
|
|
575
|
+
The active pane.
|
|
576
|
+
selection (Optional[SetPanesSelection | list[Selection]]): The selection
|
|
577
|
+
details for the panes.
|
|
578
|
+
|
|
579
|
+
Raises:
|
|
580
|
+
ValueError: If x_split or y_split is negative, or if active_pane is
|
|
581
|
+
invalid.
|
|
582
|
+
|
|
583
|
+
Returns:
|
|
584
|
+
None
|
|
585
|
+
"""
|
|
565
586
|
if x_split < 0 or y_split < 0:
|
|
566
587
|
raise ValueError('Split position should be positive.')
|
|
567
588
|
if top_left_cell != '':
|
|
@@ -709,6 +730,22 @@ class WorkSheet(WorkSheetBase):
|
|
|
709
730
|
hidden: bool = False,
|
|
710
731
|
engine: Literal['pyfastexcel', 'openpyxl'] = 'pyfastexcel',
|
|
711
732
|
):
|
|
733
|
+
"""
|
|
734
|
+
Groups columns between start_col and end_col with specified outline
|
|
735
|
+
level and visibility.
|
|
736
|
+
|
|
737
|
+
Args:
|
|
738
|
+
start_col (str): The starting column to group.
|
|
739
|
+
end_col (Optional[str]): The ending column to group. If None, only
|
|
740
|
+
start_col will be grouped.
|
|
741
|
+
outline_level (int): The outline level of the group.
|
|
742
|
+
hidden (bool): Whether the grouped columns should be hidden.
|
|
743
|
+
engine (Literal['pyfastexcel', 'openpyxl']): The engine to use for
|
|
744
|
+
grouping.
|
|
745
|
+
|
|
746
|
+
Returns:
|
|
747
|
+
None
|
|
748
|
+
"""
|
|
712
749
|
self._grouped_columns_list.append(
|
|
713
750
|
{
|
|
714
751
|
'start_col': start_col,
|
|
@@ -727,6 +764,22 @@ class WorkSheet(WorkSheetBase):
|
|
|
727
764
|
hidden: bool = False,
|
|
728
765
|
engine: Literal['pyfastexcel', 'openpyxl'] = 'pyfastexcel',
|
|
729
766
|
):
|
|
767
|
+
"""
|
|
768
|
+
Groups rows between start_row and end_row with specified outline level
|
|
769
|
+
and visibility.
|
|
770
|
+
|
|
771
|
+
Args:
|
|
772
|
+
start_row (int): The starting row to group.
|
|
773
|
+
end_row (Optional[int]): The ending row to group. If None,
|
|
774
|
+
only start_row will be grouped.
|
|
775
|
+
outline_level (int): The outline level of the group.
|
|
776
|
+
hidden (bool): Whether the grouped rows should be hidden.
|
|
777
|
+
engine (Literal['pyfastexcel', 'openpyxl']): The engine to use for
|
|
778
|
+
grouping.
|
|
779
|
+
|
|
780
|
+
Returns:
|
|
781
|
+
None
|
|
782
|
+
"""
|
|
730
783
|
self._grouped_rows_list.append(
|
|
731
784
|
{
|
|
732
785
|
'start_row': start_row,
|
|
@@ -26,13 +26,6 @@ class StreamWriter(Workbook):
|
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
28
|
def __init__(self, data: Optional[list[dict[str, str]]] = None):
|
|
29
|
-
"""
|
|
30
|
-
Initializes the NormalWriter.
|
|
31
|
-
|
|
32
|
-
Args:
|
|
33
|
-
data (list[dict[str, str]]): The data to be written to the
|
|
34
|
-
Excel file.
|
|
35
|
-
"""
|
|
36
29
|
super().__init__()
|
|
37
30
|
self._row_list = []
|
|
38
31
|
self.data = data
|
|
@@ -116,6 +109,39 @@ class StreamWriter(Workbook):
|
|
|
116
109
|
value = validate_and_format_value(value, set_default_style=False)
|
|
117
110
|
self._row_list.append((value, style))
|
|
118
111
|
|
|
112
|
+
def row_append_list(
|
|
113
|
+
self,
|
|
114
|
+
value: list[Any],
|
|
115
|
+
style: str | CustomStyle = 'DEFAULT_STYLE',
|
|
116
|
+
create_row: bool = False,
|
|
117
|
+
**kwargs,
|
|
118
|
+
) -> None:
|
|
119
|
+
"""
|
|
120
|
+
Appends a value to the row list.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
value (list[Any]): The value to be appended.
|
|
124
|
+
style (str | CustomStyle): The style of the value, can be either
|
|
125
|
+
a style name or a CustomStyle object.
|
|
126
|
+
create_row (bool): Whether to create row.
|
|
127
|
+
**kwargs: Additional keyword arguments to modify the style.
|
|
128
|
+
"""
|
|
129
|
+
self.style_key = f'{style}{kwargs}'
|
|
130
|
+
|
|
131
|
+
if isinstance(style, CustomStyle):
|
|
132
|
+
style = self._handle_custom_style(style, kwargs)
|
|
133
|
+
elif isinstance(style, str):
|
|
134
|
+
style = self._handle_string_style(style, kwargs)
|
|
135
|
+
|
|
136
|
+
if create_row:
|
|
137
|
+
value = tuple(
|
|
138
|
+
(validate_and_format_value(x, set_default_style=False), style) for x in value
|
|
139
|
+
)
|
|
140
|
+
self.workbook[self.sheet].data.append(value)
|
|
141
|
+
else:
|
|
142
|
+
value = validate_and_format_value(value, set_default_style=False)
|
|
143
|
+
self._row_list.append((value, style))
|
|
144
|
+
|
|
119
145
|
def create_row(self):
|
|
120
146
|
"""
|
|
121
147
|
Creates a row in the Excel data, and clean the current _row_list.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|