Skip to content

Commit

Permalink
fix #4: ignore potentially trailing none valued cells
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Oct 9, 2015
1 parent fb8ba36 commit 00973b4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
25 changes: 16 additions & 9 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ For individual excel file formats, please install them as you wish:
.. _a-map-of-plugins-and-file-formats:
.. table:: a map of plugins and supported excel file formats

============== ======================================= ============= ========================
Package name Supported file formats Dependencies Python versions
============== ======================================= ============= ========================
`pyexcel-io`_ csv, csvz [#f1]_, tsv, tsvz [#f2]_ 2.6, 2.7, 3.3, 3.4, pypy
`xls`_ xls, xlsx(read only), xlsm(read only) xlrd, xlwt 2.6, 2.7, 3.3, 3.4, pypy
`xlsx`_ xlsx openpyxl 2.6, 2.7, 3.3, 3.4, pypy
`ods3`_ ods ezodf, lxml 2.6, 2.7, 3.3, 3.4
`ods`_ ods (python 2.6, 2.7) odfpy 2.6, 2.7
============== ======================================= ============= ========================
============== ======================= ============= ==================
Package name Supported file formats Dependencies Python versions
============== ======================= ============= ==================
`pyexcel-io`_ csv, csvz [#f1]_, tsv, 2.6, 2.7, 3.3,
3.4, pypy
tsvz [#f2]_
`xls`_ xls, xlsx(read only), xlrd, xlwt 2.6, 2.7, 3.3,
3.4, pypy
xlsm(read only)
`xlsx`_ xlsx openpyxl 2.6, 2.7, 3.3,
3.4, pypy
`ods3`_ ods ezodf, lxml 2.6, 2.7, 3.3, 3.4
`ods`_ ods (python 2.6, 2.7) odfpy 2.6, 2.7
============== ======================= ============= ==================

Please import them before you start to access the desired file formats::

Expand All @@ -78,6 +83,8 @@ After that, you can start get and save data in the loaded format.
============= =========== ============ ============ ============
`pyexcel-io`_ `xls`_ `xlsx`_ `ods`_ `ods3`_
============= =========== ============ ============ ============
0.0.7 0.0.7 0.0.6 0.0.6+ 0.0.8
0.0.6 0.0.7 0.0.6 0.0.6+ 0.0.8
0.0.5 0.0.7 0.0.6 0.0.6+ 0.0.8
0.0.4 0.0.7 0.0.6 0.0.6 0.0.8
0.0.3 0.0.6 0.0.5 0.0.5 0.0.7
Expand Down
13 changes: 13 additions & 0 deletions doc/source/plaincsv.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Working with CSV format
================================================================================

Please note that csv reader load data in a lazy manner. It ignores excessive
trailing cells that has None value. For example, the following csv content::

1,2,,,,,
3,4,,,,,
5,,,,,,,

would end up as::

1,2
3,4
5,

Write to a csv file
--------------------------------------------------------------------------------

Expand Down
14 changes: 6 additions & 8 deletions pyexcel_io/csvbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,17 @@ def get_file_handle(self):

def to_array(self):
reader = csv.reader(self.get_file_handle(), **self.keywords)
longest_row_length = -1
array = []
for row in reader:
myrow = []
tmp_row = []
for element in row:
if PY2:
myrow.append(element.decode(self.encoding))
else:
myrow.append(element)
if longest_row_length == -1:
longest_row_length = len(myrow)
elif longest_row_length < len(myrow):
longest_row_length = len(myrow)
element = element.decode(self.encoding)
tmp_row.append(element)
if element is not None and element != '':
myrow += tmp_row
tmp_row = []
array.append(myrow)
return array

Expand Down
6 changes: 3 additions & 3 deletions tests/test_csv_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def setUp(self):
self.test_file = "csv_book." + self.file_type
self.data = [
["1"],
["4", "5", "6"],
["7"]
["4", "5", "6", "", ""],
["", "7"]
]
with open(self.test_file, 'w') as f:
for row in self.data:
Expand All @@ -297,7 +297,7 @@ def test_sheet_file_reader(self):
assert result == [
["1"],
["4", "5", "6"],
["7"]
["", "7"]
]

def tearDown(self):
Expand Down

0 comments on commit 00973b4

Please sign in to comment.