Skip to content

Commit c6407aa

Browse files
committed
fix #4, remove excessive trailing columns and empty rows underneath
1 parent a8c2841 commit c6407aa

File tree

6 files changed

+20
-62
lines changed

6 files changed

+20
-62
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ python:
1212
install:
1313
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install weakrefset; fi
1414
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install ordereddict; fi
15-
- pip install https://github.com/chfw/pyexcel/archive/master.zip
16-
- pip install https://github.com/chfw/pyexcel-io/archive/master.zip
1715
- pip install -r requirements.txt
1816
- pip install -r tests/requirements.txt
1917
script:

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
# General information about the project.
5454
project = u'pyexcel-ods3'
55-
copyright = u'2015, C.W.'
55+
copyright = u'Onni Software Ltd. and its contributors'
5656
author = u'C.W.'
5757

5858
# The version info for the project you're documenting, acts as replacement for

pyexcel_ods3/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,16 @@ def to_array(self):
103103
as an array (rows) of arrays (columns)"""
104104
table = []
105105
for row in range(self.native_sheet.nrows()):
106-
rows = []
106+
row_data = []
107+
tmp_row = []
107108
for column, cell in enumerate(self.native_sheet.row(row)):
108-
ret = self._read_cell(cell)
109-
rows.append(ret)
110-
# if row contained something
111-
table.append(rows)
109+
cell_value = self._read_cell(cell)
110+
tmp_row.append(cell_value)
111+
if cell_value is not None and cell_value != '':
112+
row_data += tmp_row
113+
tmp_row = []
114+
if len(row_data) > 0:
115+
table.append(row_data)
112116

113117
return table
114118

tests/base.py

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44

55
def create_sample_file1(file):
6-
w = pyexcel.Writer(file)
76
data=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
87
table = []
98
table.append(data[:4])
109
table.append(data[4:8])
1110
table.append(data[8:12])
12-
w.write_array(table)
13-
w.close()
11+
pyexcel.save_as(array=table, dest_file_name=file)
1412

1513

1614
class PyexcelHatWriterBase:
@@ -24,10 +22,8 @@ class PyexcelHatWriterBase:
2422
}
2523

2624
def test_series_table(self):
27-
w = pyexcel.Writer(self.testfile)
28-
w.write_dict(self.content)
29-
w.close()
30-
r = pyexcel.SeriesReader(self.testfile)
25+
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
26+
r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
3127
actual = pyexcel.utils.to_dict(r)
3228
assert actual == self.content
3329

@@ -47,40 +43,19 @@ class PyexcelWriterBase:
4743
]
4844

4945
def _create_a_file(self, file):
50-
w = pyexcel.Writer(file)
51-
w.write_array(self.content)
52-
w.close()
46+
pyexcel.save_as(dest_file_name=file,array=self.content)
5347

5448
def test_write_array(self):
5549
self._create_a_file(self.testfile)
56-
r = pyexcel.Reader(self.testfile)
50+
r = pyexcel.get_sheet(file_name=self.testfile)
5751
actual = pyexcel.utils.to_array(r.rows())
5852
assert actual == self.content
5953

60-
def test_write_reader(self):
61-
"""
62-
Use reader as data container
63-
64-
this test case shows the file written by pyexcel
65-
can be read back by itself
66-
"""
67-
self._create_a_file(self.testfile)
68-
r = pyexcel.Reader(self.testfile)
69-
w2 = pyexcel.Writer(self.testfile2)
70-
w2.write_reader(r)
71-
w2.close()
72-
r2 = pyexcel.Reader(self.testfile2)
73-
r2.format(int)
74-
actual = pyexcel.utils.to_array(r2.rows())
75-
assert actual == self.content
76-
7754

7855
class PyexcelMultipleSheetBase:
7956

8057
def _write_test_file(self, filename):
81-
w = pyexcel.BookWriter(filename)
82-
w.write_book_from_dict(self.content)
83-
w.close()
58+
pyexcel.save_book_as(bookdict=self.content, dest_file_name=filename)
8459

8560
def _clean_up(self):
8661
if os.path.exists(self.testfile2):
@@ -122,20 +97,6 @@ def test_iterate_through_sheets(self):
12297
data = pyexcel.utils.to_array(s)
12398
assert self.content[s.name] == data
12499

125-
def test_write_a_book_reader(self):
126-
b = pyexcel.BookReader(self.testfile)
127-
bw = pyexcel.BookWriter(self.testfile2)
128-
for s in b:
129-
data = pyexcel.utils.to_array(s)
130-
sheet = bw.create_sheet(s.name)
131-
sheet.write_array(data)
132-
sheet.close()
133-
bw.close()
134-
x = pyexcel.BookReader(self.testfile2)
135-
for s in x:
136-
data = pyexcel.utils.to_array(s)
137-
assert self.content[s.name] == data
138-
139100
def test_random_access_operator(self):
140101
r = pyexcel.BookReader(self.testfile)
141102
value = r["Sheet1"][0,1]

tests/test_mutliple_sheets.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def _write_test_file(self, file):
5353
3,3,3,3
5454
"""
5555
self.rows = 3
56-
w = pyexcel.BookWriter(file)
57-
w.write_book_from_dict(self.content)
58-
w.close()
56+
pyexcel.save_book_as(bookdict=self.content, dest_file_name=file)
5957

6058
def setUp(self):
6159
self.testfile = "multiple1.ods"
@@ -118,8 +116,8 @@ def test_add_book1(self):
118116
"""
119117
test this scenario: book3 = book1 + book2
120118
"""
121-
b1 = pyexcel.BookReader(self.testfile)
122-
b2 = pyexcel.BookReader(self.testfile2)
119+
b1 = pyexcel.get_book(file_name=self.testfile)
120+
b2 = pyexcel.get_book(file_name=self.testfile2)
123121
b3 = b1 + b2
124122
content = pyexcel.utils.to_dict(b3)
125123
sheet_names = content.keys()

tests/test_stringio.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def test_xls_output_stringio(self):
2929
[1, 2, 3],
3030
[4, 5, 6]
3131
]
32-
io = StringIO()
33-
w = pyexcel.Writer(("ods",io))
34-
w.write_rows(data)
35-
w.close()
32+
io = pyexcel.save_as(dest_file_type='ods', array=data)
3633
r = pyexcel.Reader(("ods", io.getvalue()))
3734
result=[1, 2, 3, 4, 5, 6]
3835
actual = pyexcel.utils.to_array(r.enumerate())

0 commit comments

Comments
 (0)