From f32a79dd82b592c9419829db9e9cbaf4d268a967 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 24 Aug 2017 13:22:13 +0200 Subject: [PATCH] [FIX] web: limit amount of rows for excel export Before this commit, when the amount of rows was above xls format threshold (>65535), the xlwt library threw an obscure Traceback to the user. We now test the amount of rows before even calling the library, raising a more helpful message to the user OPW 767319 closes #19035 --- addons/web/controllers/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 3dc9d4526bc..636f37d293e 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -35,7 +35,7 @@ from openerp.tools import ustr from openerp.tools.misc import str2bool, xlwt from openerp import http from openerp.http import request, serialize_exception as _serialize_exception, content_disposition -from openerp.exceptions import AccessError +from openerp.exceptions import AccessError, UserError _logger = logging.getLogger(__name__) @@ -1419,6 +1419,9 @@ class ExcelExport(ExportFormat, http.Controller): return base + '.xls' def from_data(self, fields, rows): + if len(rows) > 65535: + raise UserError(_('There are too many rows (%s rows, limit: 65535) to export as Excel 97-2003 (.xls) format. Consider splitting the export.') % len(rows)) + workbook = xlwt.Workbook() worksheet = workbook.add_sheet('Sheet 1')