@@ -37,12 +37,12 @@ Installation
37
37
38
38
You can install it via pip::
39
39
40
- $ pip install git+https://github.com/chfw /ezodf.git
40
+ $ pip install git+https://github.com/T0ha /ezodf.git
41
41
$ pip install pyexcel-ods3
42
42
43
43
or clone it and install it::
44
44
45
- $ pip install git+https://github.com/chfw /ezodf.git
45
+ $ pip install git+https://github.com/T0ha /ezodf.git
46
46
$ pip install git+https://github.com/chfw/pyexcel-ods3.git
47
47
$ cd pyexcel-ods3
48
48
$ python setup.py install
@@ -64,50 +64,43 @@ As a standalone library
64
64
... from StringIO import StringIO
65
65
... else :
66
66
... from io import BytesIO as StringIO
67
- >>> from pyexcel_xls import OrderedDict
67
+ >>> from pyexcel_io import OrderedDict
68
68
69
69
70
70
Write to an ods file
71
71
*********************
72
72
73
73
Here's the sample code to write a dictionary to an ods file::
74
74
75
- >>> from pyexcel_ods3 import ODSWriter
75
+ >>> from pyexcel_ods3 import store_data
76
76
>>> data = OrderedDict()
77
77
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
78
78
>>> data.update({"Sheet 2": [["row 1", "row 2", "row 3"]]})
79
- >>> writer = ODSWriter("your_file.ods")
80
- >>> writer.write(data)
81
- >>> writer.close()
79
+ >>> store_data("your_file.ods", data)
82
80
83
81
Read from an ods file
84
82
**********************
85
83
86
84
Here's the sample code::
87
85
88
- >>> from pyexcel_ods3 import ODSBook
89
- >>> book = ODSBook("your_file.ods")
90
- >>> # book.sheets() returns a dictionary of all sheet content
91
- >>> # the keys represents sheet names
92
- >>> # the values are two dimensional array
86
+ >>> from pyexcel_ods3 import load_data
87
+ >>> data = load_data("your_file.ods")
93
88
>>> import json
94
- >>> print(json.dumps(book.sheets() ))
89
+ >>> print(json.dumps(data ))
95
90
{"Sheet 1": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "Sheet 2": [["row 1", "row 2", "row 3"]]}
96
91
97
92
Write an ods file to memory
98
- *****************************
93
+ ******************************
99
94
100
95
Here's the sample code to write a dictionary to an ods file::
101
96
102
- >>> from pyexcel_ods3 import ODSWriter
97
+ >>> from pyexcel_ods3 import store_data
103
98
>>> data = OrderedDict()
104
99
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
105
100
>>> data.update({"Sheet 2": [[7, 8, 9], [10, 11, 12]]})
106
101
>>> io = StringIO()
107
- >>> writer = ODSWriter(io)
108
- >>> writer.write(data)
109
- >>> writer.close()
110
- >>> # do something witht the io
102
+ >>> store_data(io, data)
103
+ >>> # do something with the io
111
104
>>> # In reality, you might give it to your http response
112
105
>>> # object for downloading
113
106
@@ -118,10 +111,11 @@ Read from an ods from memory
118
111
Here's the sample code::
119
112
120
113
>>> # This is just an illustration
121
- >>> # In reality, you might deal with xl file upload
122
- >>> # where you will read from requests.FILES['YOUR_XL_FILE']
123
- >>> book = ODSBook(None, io.getvalue())
124
- >>> print(json.dumps(book.sheets()))
114
+ >>> # In reality, you might deal with ods file upload
115
+ >>> # where you will read from requests.FILES['YOUR_ODS_FILE']
116
+ >>> io.seek(0)
117
+ >>> data = load_data(io)
118
+ >>> print(json.dumps(data))
125
119
{"Sheet 1": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "Sheet 2": [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]}
126
120
127
121
@@ -161,19 +155,19 @@ Here is the sample code::
161
155
162
156
>>> sheet.save_as("another_file.ods")
163
157
164
- Reading from a StringIO instance
158
+ Reading from a IO instance
165
159
================================
166
160
167
161
You got to wrap the binary content with StringIO to get odf working::
168
162
169
163
170
164
>>> # This is just an illustration
171
165
>>> # In reality, you might deal with xl file upload
172
- >>> # where you will read from requests.FILES['YOUR_XL_FILE ']
173
- >>> xlfile = "another_file.ods"
174
- >>> with open(xlfile , "rb") as f:
166
+ >>> # where you will read from requests.FILES['YOUR_ODS_FILE ']
167
+ >>> odsfile = "another_file.ods"
168
+ >>> with open(odsfile , "rb") as f:
175
169
... content = f.read()
176
- ... r = pe.get_book(file_type="ods", content =content)
170
+ ... r = pe.get_book(file_type="ods", file_content =content)
177
171
... print(r)
178
172
...
179
173
Sheet Name: Sheet 1
0 commit comments