From 3278d9990e8976c6657a19d0adb4e5fd7830364d Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 12 Feb 2014 15:50:40 +0100 Subject: [PATCH] [IMP] Allow to import xlsx files --- .../parser/file_parser.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/account_statement_base_import/parser/file_parser.py b/account_statement_base_import/parser/file_parser.py index 2f4fbdaf..125605f2 100644 --- a/account_statement_base_import/parser/file_parser.py +++ b/account_statement_base_import/parser/file_parser.py @@ -35,24 +35,24 @@ def float_or_zero(val): class FileParser(BankStatementImportParser): """ - Generic abstract class for defining parser for .csv or .xls file format. + Generic abstract class for defining parser for .csv, .xls or .xlsx file format. """ def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None, **kwargs): """ :param char: parse_name: The name of the parser - :param char: ftype: extension of the file (could be csv or xls) + :param char: ftype: extension of the file (could be csv, xls or xlsx) :param dict: extra_fields: extra fields to add to the conversion dict. In the format {fieldname: fieldtype} :param list: header : specify header fields if the csv file has no header """ super(FileParser, self).__init__(parse_name, **kwargs) - if ftype in ('csv', 'xls'): - self.ftype = ftype + if ftype in ('csv', 'xls' ,'xlsx'): + self.ftype = ftype[0:3] else: raise except_osv(_('User Error'), - _('Invalid file type %s. Please use csv or xls') % ftype) + _('Invalid file type %s. Please use csv, xls or xlsx') % ftype) self.conversion_dict = { 'ref': unicode, 'label': unicode, @@ -81,7 +81,7 @@ class FileParser(BankStatementImportParser): def _parse(self, *args, **kwargs): """ - Launch the parsing through .csv or .xls depending on the + Launch the parsing through .csv, .xls or .xlsx depending on the given ftype """ @@ -128,7 +128,7 @@ class FileParser(BankStatementImportParser): def _parse_xls(self): """ - :return: dict of dict from xls file (line/rows) + :return: dict of dict from xls/xlsx file (line/rows) """ wb_file = tempfile.NamedTemporaryFile() wb_file.write(self.filebuffer) @@ -180,7 +180,7 @@ class FileParser(BankStatementImportParser): def _from_xls(self, result_set, conversion_rules): """ Handle the converstion from the dict and handle date format from - an .xls file. + an .csv, .xls or .xlsx file. """ for line in result_set: for rule in conversion_rules: