diff --git a/README.rst b/README.rst index bb1ed2a..e46b533 100644 --- a/README.rst +++ b/README.rst @@ -52,6 +52,7 @@ Write to an xls file .. testcode:: :hide: + >>> import os >>> import sys >>> if sys.version_info[0] < 3: ... from StringIO import StringIO @@ -87,6 +88,7 @@ Here's the sample code: >>> print(json.dumps(data)) {"Sheet 1": [[1, 2, 3], [4, 5, 6]], "Sheet 2": [["row 1", "row 2", "row 3"]]} + Write an xls to memory ******************************************************************************** @@ -126,6 +128,8 @@ Pagination feature Let's assume the following file is a huge xls file: +.. code-block:: python + >>> huge_data = [ ... [1, 21, 31], ... [2, 22, 32], @@ -144,16 +148,16 @@ And let's pretend to read partial data: .. code-block:: python >>> partial_data = get_data("huge_file.xls", start_row=2, row_limit=3) - >>> partial_data['huge'] - [[3, 23, 33], [4, 24, 34], [5, 25, 35]] + >>> print(json.dumps(partial_data)) + {"huge": [[3, 23, 33], [4, 24, 34], [5, 25, 35]]} And you could as well do the same for columns: .. code-block:: python >>> partial_data = get_data("huge_file.xls", start_column=1, column_limit=2) - >>> partial_data['huge'] - [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]] + >>> print(json.dumps(partial_data)) + {"huge": [[21, 31], [22, 32], [23, 33], [24, 34], [25, 35], [26, 36]]} Obvious, you could do both at the same time: @@ -162,8 +166,13 @@ Obvious, you could do both at the same time: >>> partial_data = get_data("huge_file.xls", ... start_row=2, row_limit=3, ... start_column=1, column_limit=2) - >>> partial_data['huge'] - [[23, 33], [24, 34], [25, 35]] + >>> print(json.dumps(partial_data)) + {"huge": [[23, 33], [24, 34], [25, 35]]} + +.. testcode:: + :hide: + + >>> os.unlink("huge_file.xls") As a pyexcel plugin @@ -183,6 +192,7 @@ Import it in your file to enable this plugin: Please note only pyexcel version 0.0.4+ support this. + Reading from an xls file ******************************************************************************** @@ -205,6 +215,7 @@ Here is the sample code: | row 1 | row 2 | row 3 | +-------+-------+-------+ + Writing to an xls file ******************************************************************************** @@ -214,8 +225,9 @@ Here is the sample code: >>> sheet.save_as("another_file.xls") + Reading from a IO instance -================================================================================ +******************************************************************************** You got to wrap the binary content with stream to get xls working: @@ -243,7 +255,7 @@ You got to wrap the binary content with stream to get xls working: Writing to a StringIO instance -================================================================================ +******************************************************************************** You need to pass a StringIO instance to Writer: @@ -323,5 +335,4 @@ Known Issues >>> import os >>> os.unlink("your_file.xls") - >>> os.unlink("huge_file.xls") >>> os.unlink("another_file.xls") diff --git a/pyexcel_xls/xls.py b/pyexcel_xls/xls.py index 908d260..3cbebfc 100644 --- a/pyexcel_xls/xls.py +++ b/pyexcel_xls/xls.py @@ -63,7 +63,7 @@ def xldate_to_python_date(value): class XLSheet(SheetReader): """ - xls sheet + xls, xlsx, xlsm sheet reader Currently only support first sheet in the file """ @@ -178,7 +178,7 @@ class XLSBook(BookReader): class XLSheetWriter(SheetWriter): """ - xls, xlsx and xlsm sheet writer + xls sheet writer """ def set_sheet_name(self, name): """Create a sheet @@ -190,7 +190,7 @@ class XLSheetWriter(SheetWriter): """ write a row into the file """ - for i in range(0, len(array)): + for i in range(len(array)): value = array[i] style = None tmp_array = [] @@ -221,7 +221,7 @@ class XLSheetWriter(SheetWriter): class XLSWriter(BookWriter): """ - xls, xlsx and xlsm writer + xls writer """ def __init__(self): BookWriter.__init__(self)