1
1
from collections import defaultdict
2
+ import datetime
2
3
3
- import pandas ._libs .json as json
4
+ # import pandas._libs.json as json
4
5
5
6
from pandas .io .excel ._base import ExcelWriter
6
- from pandas .io .excel ._util import _validate_freeze_panes
7
+ # from pandas.io.excel._util import _validate_freeze_panes
7
8
8
9
from odf .opendocument import OpenDocumentSpreadsheet
9
10
from odf .table import Table , TableRow , TableCell
10
11
from odf .text import P
11
12
13
+
12
14
class _ODSWriter (ExcelWriter ):
13
15
engine = "odf"
14
16
supported_extensions = (".ods" ,)
@@ -24,8 +26,9 @@ def __init__(self, path, engine=None, encoding=None, mode="w", **engine_kwargs):
24
26
if encoding is None :
25
27
encoding = "ascii"
26
28
self .book = OpenDocumentSpreadsheet ()
27
- # self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format)
28
- # self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
29
+
30
+ # self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format)
31
+ # self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
29
32
30
33
def save (self ):
31
34
"""
@@ -46,31 +49,49 @@ def write_cells(
46
49
wks = self .sheets [sheet_name ]
47
50
else :
48
51
wks = Table (name = sheet_name )
49
- # wks = self.book.add_sheet(sheet_name) (do at the end or immediately? FIXME)
52
+ # wks = self.book.add_sheet(sheet_name) (do at the end or immediately? FIXME)
50
53
self .sheets [sheet_name ] = wks
51
54
52
- # if _validate_freeze_panes(freeze_panes):
53
- # wks.set_panes_frozen(True)
54
- # wks.set_horz_split_pos(freeze_panes[0])
55
- # wks.set_vert_split_pos(freeze_panes[1])
55
+ # if _validate_freeze_panes(freeze_panes):
56
+ # wks.set_panes_frozen(True)
57
+ # wks.set_horz_split_pos(freeze_panes[0])
58
+ # wks.set_vert_split_pos(freeze_panes[1])
56
59
57
60
style_dict = {}
58
61
59
62
rows = defaultdict (TableRow )
60
63
col_count = defaultdict (int )
61
64
62
65
for cell in cells :
63
- print (cell .row , cell .col , cell .val )
66
+ # print(cell.row, cell.col, cell.val)
64
67
# fill with empty cells if needed
65
68
for _ in range (cell .col - col_count [cell .row ]):
66
69
rows [cell .row ].addElement (TableCell ())
67
70
col_count [cell .row ] += 1
68
- class_to_cell_type = { str : "string" , int : "float" , float : "float" , bool : "boolean" }
71
+ class_to_cell_type = {
72
+ str : "string" ,
73
+ int : "float" ,
74
+ float : "float" ,
75
+ bool : "boolean" ,
76
+ }
69
77
val , fmt = self ._value_with_fmt (cell .val )
70
- tc = TableCell (valuetype = class_to_cell_type [type (val )], value = val )
78
+ # print("type", type(val), "value", val)
79
+ value = val
80
+ if isinstance (val , bool ):
81
+ value = str (val ).lower ()
82
+ # if isinstance(val, datetime.date):
83
+ # tc = TableCell(valuetype="date",
84
+ if isinstance (val , datetime .date ):
85
+ print ('date' , val .strftime ("%Y-%m-%d" ), val .strftime ("%x" ))
86
+ value = val .strftime ("%Y-%m-%d" )
87
+ tc = TableCell (valuetype = "date" , datevalue = value )
88
+ else :
89
+ tc = TableCell (valuetype = class_to_cell_type [type (val )], value = value )
71
90
rows [cell .row ].addElement (tc )
72
91
col_count [cell .row ] += 1
73
- p = P (text = val )
92
+ if isinstance (val , bool ):
93
+ value = str (val ).upper ()
94
+ p = P (text = value )
74
95
tc .addElement (p )
75
96
"""
76
97
stylekey = json.dumps(cell.style)
0 commit comments