Skip to content

Commit f8d76ba

Browse files
committed
fix #16: where only stream instance could be passed to file_stream whereas using read() applies to both stream and file handle
1 parent 0474acf commit f8d76ba

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pyexcel_xls/xls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ def _get_book(self, on_demand=False):
126126
if self._file_name:
127127
xls_book = xlrd.open_workbook(self._file_name, on_demand=on_demand)
128128
elif self._file_stream:
129+
self._file_stream.seek(0)
130+
file_content = self._file_stream.read()
129131
xls_book = xlrd.open_workbook(
130132
None,
131-
file_contents=self._file_stream.getvalue(),
133+
file_contents=file_content,
132134
on_demand=on_demand
133135
)
134136
elif self._file_content is not None:

tests/test_bug_fixes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,11 @@ def test_issue_13_empty_file_content():
6262
pe.get_sheet(file_content='', file_type='xls')
6363

6464

65+
def test_issue_16_file_stream_has_no_getvalue():
66+
test_file = get_fixture("hidden_sheets.xls")
67+
with open(test_file, 'rb') as f:
68+
pe.get_sheet(file_stream=f, file_type='xls')
69+
70+
6571
def get_fixture(file_name):
6672
return os.path.join("tests", "fixtures", file_name)

0 commit comments

Comments
 (0)