Update signature functions

This commit is contained in:
chfw 2015-05-12 14:01:27 +01:00
parent ac0f272897
commit 0e921f8bbe
2 changed files with 17 additions and 26 deletions

View File

@ -66,19 +66,19 @@ Write to an xls file
Here's the sample code to write a dictionary to an xls file::
>>> from pyexcel_xls import store_data
>>> from pyexcel_xls import save_data
>>> data = OrderedDict() # from collections import OrderedDict
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
>>> data.update({"Sheet 2": [["row 1", "row 2", "row 3"]]})
>>> store_data("your_file.xls", data)
>>> save_data("your_file.xls", data)
Read from an xls file
**********************
Here's the sample code::
>>> from pyexcel_xls import load_data
>>> data = load_data("your_file.xls")
>>> from pyexcel_xls import get_data
>>> data = get_data("your_file.xls")
>>> import json
>>> print(json.dumps(data))
{"Sheet 1": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "Sheet 2": [["row 1", "row 2", "row 3"]]}
@ -88,12 +88,12 @@ Write an xls to memory
Here's the sample code to write a dictionary to an xls file::
>>> from pyexcel_xls import store_data
>>> from pyexcel_xls import save_data
>>> data = OrderedDict()
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
>>> data.update({"Sheet 2": [[7, 8, 9], [10, 11, 12]]})
>>> io = StringIO()
>>> writer = store_data(io, data)
>>> writer = save_data(io, data)
>>> # do something with the io
>>> # In reality, you might give it to your http response
>>> # object for downloading
@ -107,7 +107,7 @@ Continue from previous example::
>>> # This is just an illustration
>>> # In reality, you might deal with xls file upload
>>> # where you will read from requests.FILES['YOUR_XL_FILE']
>>> data = load_data(io)
>>> data = get_data(io)
>>> print(json.dumps(data))
{"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]]}

View File

@ -19,6 +19,7 @@ from pyexcel_io import (
READERS,
WRITERS,
isstream,
is_string,
load_data as read_data,
store_data as write_data
)
@ -216,33 +217,23 @@ READERS.update({
"xlsm": XLBook,
"xlsx": XLBook
})
WRITERS.update({
"xls": XLWriter
})
def is_string(atype):
"""find out if a type is str or not"""
if atype == str:
return True
elif PY2:
if atype == unicode:
return True
elif atype == str:
return True
return False
def store_data(afile, data, file_type=None, **keywords):
if isstream(afile) and file_type is None:
file_type='xls'
write_data(afile, data, file_type=file_type, **keywords)
def load_data(afile, file_type=None, **keywords):
def get_data(afile, file_type=None, **keywords):
if isstream(afile) and file_type is None:
file_type='xls'
return read_data(afile, file_type=file_type, **keywords)
def save_data(afile, data, file_type=None, **keywords):
if isstream(afile) and file_type is None:
file_type='xls'
write_data(afile, data, file_type=file_type, **keywords)
__VERSION__ = "0.0.7"