summaryrefslogtreecommitdiffstats
path: root/src/python/ods.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:48:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:48:59 +0000
commitc484829272cd13a738e35412498e12f2c9a194ac (patch)
treea1f5ec09629ee895bd3963fa8820b45f2f4c574b /src/python/ods.cpp
parentInitial commit. (diff)
downloadliborcus-upstream.tar.xz
liborcus-upstream.zip
Adding upstream version 0.19.2.upstream/0.19.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/python/ods.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/python/ods.cpp b/src/python/ods.cpp
new file mode 100644
index 0000000..0a7f5ad
--- /dev/null
+++ b/src/python/ods.cpp
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ */
+
+#include "ods.hpp"
+#include "global.hpp"
+
+#ifdef __ORCUS_PYTHON_ODS
+#include "document.hpp"
+#include "orcus/orcus_ods.hpp"
+#include "orcus/spreadsheet/document.hpp"
+#include "orcus/spreadsheet/factory.hpp"
+#endif
+
+namespace orcus { namespace python {
+
+#ifdef __ORCUS_PYTHON_ODS
+
+PyObject* ods_read(PyObject* /*module*/, PyObject* args, PyObject* kwargs)
+{
+ stream_with_formulas data = read_stream_and_formula_params_from_args(args, kwargs);
+ if (!data.stream)
+ return nullptr;
+
+ try
+ {
+ spreadsheet::range_size_t ss{1048576, 16384};
+ std::unique_ptr<spreadsheet::document> doc = std::make_unique<spreadsheet::document>(ss);
+ spreadsheet::import_factory fact(*doc);
+ fact.set_recalc_formula_cells(data.recalc_formula_cells);
+ fact.set_formula_error_policy(data.error_policy);
+ orcus_ods app(&fact);
+
+ return import_from_stream_into_document(data.stream.get(), app, std::move(doc));
+ }
+ catch (const std::exception& e)
+ {
+ set_python_exception(PyExc_RuntimeError, e);
+ return nullptr;
+ }
+}
+
+#else
+
+PyObject* ods_read(PyObject*, PyObject*, PyObject*)
+{
+ PyErr_SetString(PyExc_RuntimeError, "The ods module is not enabled.");
+ return nullptr;
+}
+
+#endif
+
+}}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */