|
8 | 8 | from tempfile import NamedTemporaryFile
|
9 | 9 |
|
10 | 10 | from mfr.extensions.tabular import compat
|
11 |
| -from mfr.core.exceptions import SubprocessError, TooBigToRenderError |
| 11 | +from mfr.core.exceptions import SubprocessError, TooBigToRenderError, CorruptedError |
12 | 12 | from mfr.extensions.tabular.settings import (PSPP_CONVERT_BIN,
|
13 | 13 | PSPP_CONVERT_TIMEOUT)
|
14 | 14 |
|
@@ -143,28 +143,22 @@ def parse_xls(wb, sheets):
|
143 | 143 | def parse_xlsx(wb, sheets):
|
144 | 144 | for name in wb.sheetnames:
|
145 | 145 | ws = wb[name]
|
146 |
| - max_row = ws.max_row or 0 |
147 |
| - max_col = ws.max_column or 0 |
148 |
| - verify_size(max_row, max_col, '.xlsx') |
149 |
| - |
150 |
| - if max_row == 0 or max_col == 0: |
151 |
| - sheets[name] = ([], []) |
152 |
| - continue |
153 |
| - |
154 | 146 | header_row = next(ws.iter_rows(max_row=1, values_only=True), [])
|
155 | 147 | fields = fix_headers(header_row)
|
156 | 148 | rows = [
|
157 | 149 | dict(zip(fields, row))
|
158 | 150 | for row in ws.iter_rows(min_row=2,
|
159 |
| - max_row=max_row, |
160 |
| - max_col=max_col, |
| 151 | + max_row=MAX_SIZE, |
| 152 | + max_col=MAX_SIZE, |
161 | 153 | values_only=True)
|
162 | 154 | ]
|
163 | 155 | sheets[name] = (header_population(fields), rows)
|
164 | 156 | return sheets
|
165 | 157 |
|
166 | 158 |
|
167 | 159 | def verify_size(rows, cols, ext):
|
| 160 | + if rows is None or cols is None: |
| 161 | + raise CorruptedError |
168 | 162 | if rows > MAX_SIZE or cols > MAX_SIZE:
|
169 | 163 | raise TooBigToRenderError('Table is too large to render.', ext,
|
170 | 164 | nbr_cols=cols, nbr_rows=rows)
|
|
0 commit comments