From c484829272cd13a738e35412498e12f2c9a194ac Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:48:59 +0200 Subject: Adding upstream version 0.19.2. Signed-off-by: Daniel Baumann --- misc/file-processor-modules/preview.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 misc/file-processor-modules/preview.py (limited to 'misc/file-processor-modules') diff --git a/misc/file-processor-modules/preview.py b/misc/file-processor-modules/preview.py new file mode 100644 index 0000000..244d8ce --- /dev/null +++ b/misc/file-processor-modules/preview.py @@ -0,0 +1,33 @@ +######################################################################## +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +######################################################################## + +import orcus +from orcus.tools.file_processor import config + + +def process_document(filepath, doc): + buf = list() + for sh in doc.sheets: + try: + buf.append(f"sheet: {sh.name}") + for i, row in enumerate(sh.get_rows()): + if i > 9: + # Only display the first 10 rows. + buf.append("...") + break + + row_s = list() + for cell in row: + v = cell.value if cell.value else "" + row_s.append(str(v)) + row_s = ",".join(row_s) + buf.append(f"row {i}: {row_s}") + except Exception as e: + buf.append(f"???: (exception: {e})") + + return buf -- cgit v1.2.3