diff --git a/benedict/serializers/xls.py b/benedict/serializers/xls.py index 64ce785..bb52999 100644 --- a/benedict/serializers/xls.py +++ b/benedict/serializers/xls.py @@ -52,10 +52,15 @@ class XLSSerializer(AbstractSerializer): return list(range(columns_count)) def _decode_legacy(self, s, **kwargs): - filepath = s + options = {} + options["filename"] = s + options["logfile"] = kwargs.pop("logfile", None) + options["verbosity"] = kwargs.pop("verbosity", 0) or 0 + options["use_mmap"] = kwargs.pop("use_mmap", False) or False + options["file_contents"] = kwargs.pop("file_contents", None) # load the worksheet - workbook = open_workbook(filename=filepath) + workbook = open_workbook(**options) # get sheet by index or by name sheet_index, sheet_name = self._get_sheet_index_and_name_from_options(**kwargs) @@ -100,10 +105,15 @@ class XLSSerializer(AbstractSerializer): return items def _decode(self, s, **kwargs): - filepath = s + options = {} + options["filename"] = s + options["read_only"] = True + options["data_only"] = kwargs.pop("data_only", False) + options["keep_links"] = kwargs.pop("keep_links", True) + options["keep_vba"] = kwargs.pop("keep_vba", True) # load the worksheet - workbook = load_workbook(filename=filepath, read_only=True) + workbook = load_workbook(**options) # get sheet by index or by name sheet_index, sheet_name = self._get_sheet_index_and_name_from_options(**kwargs) diff --git a/tests/github/test_issue_0355.py b/tests/github/test_issue_0355.py new file mode 100644 index 0000000..dcc6536 --- /dev/null +++ b/tests/github/test_issue_0355.py @@ -0,0 +1,48 @@ +import pathlib +import unittest + +from benedict import benedict + + +class github_issue_0355_test_case(unittest.TestCase): + """ + This class describes a github issue 0355 test case. + https://github.com/fabiocaccamo/python-benedict/issues/355 + + To run this specific test: + - Run python -m unittest tests.github.test_issue_0355 + """ + + def test_from_xls_with_options(self): + # print(pathlib.Path("./test_issue_0144.json")) + filepath = pathlib.Path("tests/github/test_issue_0355.xlsx") + + d = benedict.from_xls(filepath) + # print(d.dump()) + self.assertEqual( + d, + { + "values": [ + { + "formula": '="A2 value is: "&A2', + "integer": 123, + "text": "abc", + } + ] + }, + ) + + d = benedict.from_xls(filepath, data_only=True) + # print(d.dump()) + self.assertEqual( + d, + { + "values": [ + { + "formula": "A2 value is: abc", + "integer": 123, + "text": "abc", + } + ] + }, + ) diff --git a/tests/github/test_issue_0355.xlsx b/tests/github/test_issue_0355.xlsx new file mode 100644 index 0000000..2efd9d9 Binary files /dev/null and b/tests/github/test_issue_0355.xlsx differ