Skip to content

Commit cc806df

Browse files
committed
release 0.5.3 🥚 🎡, skip hidden rows and columns
2 parents c3b6c65 + 66aece6 commit cc806df

File tree

10 files changed

+86
-18
lines changed

10 files changed

+86
-18
lines changed

.moban.d/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
{%block description%}
77
**pyexcel-{{file_type}}** is a tiny wrapper library to read, manipulate and write data in {{file_type}} format and it can read xlsx and xlsm fromat. You are likely to use it with `pyexcel <https://github.com/pyexcel/pyexcel>`_.
8+
9+
New flag: `skip_hidden_row_and_column=True` allow you to skip hidden rows and columns. It may slow down its reading performance.
10+
811
{%endblock%}
912

1013
{%block extras %}

CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Change log
22
================================================================================
33

4+
0.5.3 - 2.11.2017
5+
--------------------------------------------------------------------------------
6+
7+
Added
8+
********************************************************************************
9+
10+
#. `#21 <https://github.com/pyexcel/pyexcel-xls/issues/21>`_, skip hidden rows
11+
and columns under 'skip_hidden_row_and_column' flag.
12+
413
0.5.2 - 23.10.2017
514
--------------------------------------------------------------------------------
615

@@ -19,6 +28,8 @@ added
1928

2029
#. `#103 <https://github.com/pyexcel/pyexcel/issues/103>`_, include LICENSE file
2130
in MANIFEST.in, meaning LICENSE file will appear in the released tar ball.
31+
=======
32+
2233

2334
0.5.0 - 30.08.2017
2435
--------------------------------------------------------------------------------

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pyexcel-xls - Let you focus on data, instead of xls format
1717

1818
**pyexcel-xls** is a tiny wrapper library to read, manipulate and write data in xls format and it can read xlsx and xlsm fromat. You are likely to use it with `pyexcel <https://github.com/pyexcel/pyexcel>`_.
1919

20+
New flag: `skip_hidden_row_and_column=True` allow you to skip hidden rows and columns. It may slow down its reading performance.
21+
22+
2023
Known constraints
2124
==================
2225

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
project = u'pyexcel-xls'
2323
copyright = u'2015-2017 Onni Software Ltd.'
24-
version = '0.5.2'
25-
release = '0.5.2'
24+
version = '0.5.3'
25+
release = '0.5.3'
2626
exclude_patterns = []
2727
pygments_style = 'sphinx'
2828
html_theme = 'default'

pyexcel_xls.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
overrides: "pyexcel.yaml"
22
name: "pyexcel-xls"
33
nick_name: xls
4-
version: 0.5.2
5-
current_version: 0.5.2
6-
release: 0.5.2
4+
version: 0.5.3
5+
current_version: 0.5.3
6+
release: 0.5.3
77
file_type: xls
88
dependencies:
99
- pyexcel-io>=0.5.3

pyexcel_xls/xlsr.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ class XLSheet(SheetReader):
3232
def __init__(self, sheet, auto_detect_int=True, **keywords):
3333
SheetReader.__init__(self, sheet, **keywords)
3434
self.__auto_detect_int = auto_detect_int
35+
self.__hidden_cols = []
36+
self.__hidden_rows = []
37+
if keywords.get('skip_hidden_row_and_column') is True:
38+
for col_index, info in self._native_sheet.colinfo_map.items():
39+
if info.hidden == 1:
40+
self.__hidden_cols.append(col_index)
41+
for row_index, info in self._native_sheet.rowinfo_map.items():
42+
if info.hidden == 1:
43+
self.__hidden_rows.append(row_index)
3544

3645
@property
3746
def name(self):
@@ -41,18 +50,19 @@ def number_of_rows(self):
4150
"""
4251
Number of rows in the xls sheet
4352
"""
44-
return self._native_sheet.nrows
53+
return self._native_sheet.nrows - len(self.__hidden_rows)
4554

4655
def number_of_columns(self):
4756
"""
4857
Number of columns in the xls sheet
4958
"""
50-
return self._native_sheet.ncols
59+
return self._native_sheet.ncols - len(self.__hidden_cols)
5160

5261
def cell_value(self, row, column):
5362
"""
5463
Random access to the xls cells
5564
"""
65+
row, column = self._offset_hidden_indices(row, column)
5666
cell_type = self._native_sheet.cell_type(row, column)
5767
value = self._native_sheet.cell_value(row, column)
5868
if cell_type == xlrd.XL_CELL_DATE:
@@ -62,6 +72,19 @@ def cell_value(self, row, column):
6272
value = int(value)
6373
return value
6474

75+
def _offset_hidden_indices(self, row, column):
76+
row = calculate_offsets(row, self.__hidden_rows)
77+
column = calculate_offsets(column, self.__hidden_cols)
78+
return row, column
79+
80+
81+
def calculate_offsets(incoming_index, hidden_indices):
82+
offset = 0
83+
for index in hidden_indices:
84+
if index <= (incoming_index + offset):
85+
offset += 1
86+
return incoming_index + offset
87+
6588

6689
class XLSBook(BookReader):
6790
"""
@@ -72,19 +95,26 @@ class XLSBook(BookReader):
7295
def __init__(self):
7396
BookReader.__init__(self)
7497
self._file_content = None
98+
self.__skip_hidden_sheets = True
99+
self.__skip_hidden_row_column = True
75100

76-
def open(self, file_name, skip_hidden_sheets=True, **keywords):
101+
def open(self, file_name, **keywords):
102+
self.__parse_keywords(**keywords)
77103
BookReader.open(self, file_name, **keywords)
78-
self.__skip_hidden_sheets = skip_hidden_sheets
79104

80-
def open_stream(self, file_stream, skip_hidden_sheets=True, **keywords):
105+
def open_stream(self, file_stream, **keywords):
106+
self.__parse_keywords(**keywords)
81107
BookReader.open_stream(self, file_stream, **keywords)
82-
self.__skip_hidden_sheets = skip_hidden_sheets
83108

84-
def open_content(self, file_content, skip_hidden_sheets=True, **keywords):
109+
def open_content(self, file_content, **keywords):
110+
self.__parse_keywords(**keywords)
85111
self._keywords = keywords
86112
self._file_content = file_content
87-
self.__skip_hidden_sheets = skip_hidden_sheets
113+
114+
def __parse_keywords(self, **keywords):
115+
self.__skip_hidden_sheets = keywords.get('skip_hidden_sheets', True)
116+
self.__skip_hidden_row_column = keywords.get(
117+
'skip_hidden_row_and_column', True)
88118

89119
def close(self):
90120
if self._native_book:
@@ -131,6 +161,8 @@ def _get_book(self, on_demand=False):
131161
xlrd_params['file_contents'] = self._file_content
132162
else:
133163
raise IOError("No valid file name or file content found.")
164+
if self.__skip_hidden_row_column:
165+
xlrd_params['formatting_info'] = True
134166
xls_book = xlrd.open_workbook(**xlrd_params)
135167
return xls_book
136168

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
NAME = 'pyexcel-xls'
1111
AUTHOR = 'C.W.'
12-
VERSION = '0.5.2'
12+
VERSION = '0.5.3'
1313
EMAIL = 'wangc_2011@hotmail.com'
1414
LICENSE = 'New BSD'
1515
DESCRIPTION = (
@@ -18,7 +18,7 @@
1818
''
1919
)
2020
URL = 'https://github.com/pyexcel/pyexcel-xls'
21-
DOWNLOAD_URL = '%s/archive/0.5.2.tar.gz' % URL
21+
DOWNLOAD_URL = '%s/archive/0.5.3.tar.gz' % URL
2222
FILES = ['README.rst', 'CHANGELOG.rst']
2323
KEYWORDS = [
2424
'xls',
@@ -55,11 +55,12 @@
5555
# You do not need to read beyond this line
5656
PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format(
5757
sys.executable)
58-
GS_COMMAND = ('gs pyexcel-xls v0.5.2 ' +
59-
"Find 0.5.2 in changelog for more details")
58+
GS_COMMAND = ('gs pyexcel-xls v0.5.3 ' +
59+
"Find 0.5.3 in changelog for more details")
6060
NO_GS_MESSAGE = ('Automatic github release is disabled. ' +
6161
'Please install gease to enable it.')
62-
UPLOAD_FAILED_MSG = ('Upload failed. please run "%s" yourself.')
62+
UPLOAD_FAILED_MSG = (
63+
'Upload failed. please run "%s" yourself.' % PUBLISH_COMMAND)
6364
HERE = os.path.abspath(os.path.dirname(__file__))
6465

6566

6 KB
Binary file not shown.

tests/fixtures/hidden.xls

25 KB
Binary file not shown.

tests/test_hidden.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
from nose.tools import eq_
3+
from pyexcel_xls import get_data
4+
5+
6+
def test_simple_hidden_sheets():
7+
data = get_data(os.path.join("tests", "fixtures", "hidden.xls"),
8+
skip_hidden_row_and_column=True)
9+
expected = [[1, 3], [7, 9]]
10+
eq_(data['Sheet1'], expected)
11+
12+
13+
def test_complex_hidden_sheets():
14+
data = get_data(
15+
os.path.join("tests", "fixtures", "complex_hidden_sheets.xls"),
16+
skip_hidden_row_and_column=True)
17+
expected = [[1, 3, 5, 7, 9], [31, 33, 35, 37, 39], [61, 63, 65, 67]]
18+
eq_(data['Sheet1'], expected)

0 commit comments

Comments
 (0)