1
1
from collections import defaultdict
2
2
import datetime
3
- from typing import DefaultDict , Dict
3
+ from typing import Any , DefaultDict , Dict , List , Tuple
4
4
5
5
import pandas ._libs .json as json
6
6
@@ -12,7 +12,8 @@ class _ODSWriter(ExcelWriter):
12
12
engine = "odf"
13
13
supported_extensions = (".ods" ,)
14
14
15
- def __init__ (self , path , engine = None , encoding = None , mode = "w" , ** engine_kwargs ):
15
+ def __init__ (self , path : str , engine : Dict = None , mode : str = "w" ,
16
+ ** engine_kwargs ):
16
17
from odf .opendocument import OpenDocumentSpreadsheet
17
18
18
19
engine_kwargs ["engine" ] = engine
@@ -25,17 +26,18 @@ def __init__(self, path, engine=None, encoding=None, mode="w", **engine_kwargs):
25
26
self .book = OpenDocumentSpreadsheet ()
26
27
self ._style_dict : Dict [str , str ] = {}
27
28
28
- def save (self ):
29
+ def save (self ) -> None :
29
30
"""
30
31
Save workbook to disk.
31
32
"""
32
33
for sheet in self .sheets .values ():
33
34
self .book .spreadsheet .addElement (sheet )
34
- return self .book .save (self .path )
35
+ self .book .save (self .path )
35
36
36
37
def write_cells (
37
- self , cells , sheet_name = None , startrow = 0 , startcol = 0 , freeze_panes = None
38
- ):
38
+ self , cells , sheet_name : str = None , startrow : int = 0 , startcol : int = 0 ,
39
+ freeze_panes : List = None
40
+ ) -> None :
39
41
"""
40
42
Write the frame cells using odf
41
43
"""
@@ -80,7 +82,19 @@ def write_cells(
80
82
for row_nr in range (max (rows .keys ()) + 1 ):
81
83
wks .addElement (rows [row_nr ])
82
84
83
- def _make_table_cell_attributes (self , cell ):
85
+ def _make_table_cell_attributes (self , cell ) -> Dict [str , object ]:
86
+ """Convert cell attributes to OpenDocument attributes
87
+
88
+ Parameters
89
+ ----------
90
+ cell : ExcelCell
91
+ Spreadsheet cell data
92
+
93
+ Returns
94
+ -------
95
+ attributes : Dict[str, object]
96
+ Dictionary with attributes and attribute values
97
+ """
84
98
attributes = {}
85
99
style_name = self ._process_style (cell .style )
86
100
if style_name is not None :
@@ -90,7 +104,19 @@ def _make_table_cell_attributes(self, cell):
90
104
attributes ["numbercolumnsspanned" ] = cell .mergeend
91
105
return attributes
92
106
93
- def _make_table_cell (self , cell ):
107
+ def _make_table_cell (self , cell ) -> Tuple [str , object ]:
108
+ """Convert cell data to an OpenDocument spreadsheet cell
109
+
110
+ Parameters
111
+ ----------
112
+ cell : ExcelCell
113
+ Spreadsheet cell data
114
+
115
+ Returns
116
+ -------
117
+ pvalue, cell : Tuple[str, object]
118
+ Display value, Cell value
119
+ """
94
120
from odf .table import TableCell
95
121
96
122
attributes = self ._make_table_cell_attributes (cell )
@@ -129,7 +155,19 @@ def _make_table_cell(self, cell):
129
155
),
130
156
)
131
157
132
- def _process_style (self , style ):
158
+ def _process_style (self , style : Dict [str , Any ]) -> str :
159
+ """Convert a style dictionary to a OpenDocument style sheet
160
+
161
+ Parameters
162
+ ----------
163
+ style : Dict
164
+ Style dictionary
165
+
166
+ Returns
167
+ -------
168
+ style_key : str
169
+ Unique style key for for later reference in sheet
170
+ """
133
171
from odf .style import (
134
172
ParagraphProperties ,
135
173
Style ,
@@ -169,7 +207,16 @@ def _process_style(self, style):
169
207
self .book .styles .addElement (odf_style )
170
208
return name
171
209
172
- def _create_freeze_panes (self , sheet_name , freeze_panes ):
210
+ def _create_freeze_panes (self , sheet_name : str , freeze_panes : List [int ]) -> None :
211
+ """Create freeze panes in the sheet
212
+
213
+ Parameters
214
+ ----------
215
+ sheet_name : str
216
+ Name of the spreadsheet
217
+ freeze_panes : list
218
+ Freeze pane location x and y
219
+ """
173
220
from odf .config import (
174
221
ConfigItem ,
175
222
ConfigItemMapEntry ,
0 commit comments