@@ -52,6 +52,7 @@ Write to an xls file
52
52
.. testcode ::
53
53
:hide:
54
54
55
+ >>> import os
55
56
>>> import sys
56
57
>>> if sys.version_info[0 ] < 3 :
57
58
... from StringIO import StringIO
@@ -87,6 +88,7 @@ Here's the sample code:
87
88
>> > print (json.dumps(data))
88
89
{" Sheet 1" : [[1 , 2 , 3 ], [4 , 5 , 6 ]], " Sheet 2" : [[" row 1" , " row 2" , " row 3" ]]}
89
90
91
+
90
92
Write an xls to memory
91
93
********************************************************************************
92
94
@@ -126,6 +128,8 @@ Pagination feature
126
128
127
129
Let's assume the following file is a huge xls file:
128
130
131
+ .. code-block :: python
132
+
129
133
>> > huge_data = [
130
134
... [1 , 21 , 31 ],
131
135
... [2 , 22 , 32 ],
@@ -144,16 +148,16 @@ And let's pretend to read partial data:
144
148
.. code-block :: python
145
149
146
150
>> > partial_data = get_data(" huge_file.xls" , start_row = 2 , row_limit = 3 )
147
- >> > partial_data[ ' huge ' ]
148
- [[3 , 23 , 33 ], [4 , 24 , 34 ], [5 , 25 , 35 ]]
151
+ >> > print (json.dumps( partial_data))
152
+ { " huge " : [[3 , 23 , 33 ], [4 , 24 , 34 ], [5 , 25 , 35 ]]}
149
153
150
154
And you could as well do the same for columns:
151
155
152
156
.. code-block :: python
153
157
154
158
>> > partial_data = get_data(" huge_file.xls" , start_column = 1 , column_limit = 2 )
155
- >> > partial_data[ ' huge ' ]
156
- [[21 , 31 ], [22 , 32 ], [23 , 33 ], [24 , 34 ], [25 , 35 ], [26 , 36 ]]
159
+ >> > print (json.dumps( partial_data))
160
+ { " huge " : [[21 , 31 ], [22 , 32 ], [23 , 33 ], [24 , 34 ], [25 , 35 ], [26 , 36 ]]}
157
161
158
162
Obvious, you could do both at the same time:
159
163
@@ -162,8 +166,13 @@ Obvious, you could do both at the same time:
162
166
>> > partial_data = get_data(" huge_file.xls" ,
163
167
... start_row = 2 , row_limit = 3 ,
164
168
... start_column = 1 , column_limit = 2 )
165
- >> > partial_data[' huge' ]
166
- [[23 , 33 ], [24 , 34 ], [25 , 35 ]]
169
+ >> > print (json.dumps(partial_data))
170
+ {" huge" : [[23 , 33 ], [24 , 34 ], [25 , 35 ]]}
171
+
172
+ .. testcode ::
173
+ :hide:
174
+
175
+ >>> os.unlink(" huge_file.xls" )
167
176
168
177
169
178
As a pyexcel plugin
@@ -183,6 +192,7 @@ Import it in your file to enable this plugin:
183
192
184
193
Please note only pyexcel version 0.0.4+ support this.
185
194
195
+
186
196
Reading from an xls file
187
197
********************************************************************************
188
198
@@ -205,6 +215,7 @@ Here is the sample code:
205
215
| row 1 | row 2 | row 3 |
206
216
+ ------ -+ ------ -+ ------ -+
207
217
218
+
208
219
Writing to an xls file
209
220
********************************************************************************
210
221
@@ -214,8 +225,9 @@ Here is the sample code:
214
225
215
226
>> > sheet.save_as(" another_file.xls" )
216
227
228
+
217
229
Reading from a IO instance
218
- ================================================================================
230
+ ********************************************************************************
219
231
220
232
You got to wrap the binary content with stream to get xls working:
221
233
@@ -243,7 +255,7 @@ You got to wrap the binary content with stream to get xls working:
243
255
244
256
245
257
Writing to a StringIO instance
246
- ================================================================================
258
+ ********************************************************************************
247
259
248
260
You need to pass a StringIO instance to Writer:
249
261
@@ -323,5 +335,4 @@ Known Issues
323
335
324
336
>>> import os
325
337
>>> os.unlink(" your_file.xls" )
326
- >>> os.unlink(" huge_file.xls" )
327
338
>>> os.unlink(" another_file.xls" )
0 commit comments