Skip to content

Commit

Permalink
update pyexcel-io version
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 20, 2015
2 parents 61261d3 + 0e921f8 commit fcbe9a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]}
Expand All @@ -88,7 +88,7 @@ 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]]})
Expand All @@ -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]]}

Expand Down
23 changes: 7 additions & 16 deletions pyexcel_xls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
READERS,
WRITERS,
isstream,
is_string,
load_data as read_data,
store_data as write_data
)
Expand Down Expand Up @@ -216,33 +217,23 @@ def close(self):
"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):
def get_data(afile, file_type=None, **keywords):
if isstream(afile) and file_type is None:
file_type='xls'
write_data(afile, data, file_type=file_type, **keywords)
return read_data(afile, file_type=file_type, **keywords)


def load_data(afile, file_type=None, **keywords):
def save_data(afile, data, file_type=None, **keywords):
if isstream(afile) and file_type is None:
file_type='xls'
return read_data(afile, file_type=file_type, **keywords)
write_data(afile, data, file_type=file_type, **keywords)


__VERSION__ = "0.0.7"

0 comments on commit fcbe9a8

Please sign in to comment.