summaryrefslogtreecommitdiff
path: root/sc/source/filter/orcus
diff options
context:
space:
mode:
authorJaskaran Singh <jvsg1303@gmail.com>2016-07-12 17:32:19 +0530
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-09-18 00:15:11 +0200
commit2aea6d519ff7e487af0b2a39d78e00c0227799af (patch)
tree9cf0bed66193d96055c878bd844702ce0ceb430d /sc/source/filter/orcus
parent7911f21cd3e0deb6c1966dc97b8a5e5cf994d3af (diff)
Add a method to import ODF styles via orcus
Change-Id: Id76593bbb9982ec6745737ade800ae669e8e4471
Diffstat (limited to 'sc/source/filter/orcus')
-rw-r--r--sc/source/filter/orcus/orcusfiltersimpl.cxx40
1 files changed, 39 insertions, 1 deletions
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index c86ca3b68d23..e16cc7f1e077 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -17,14 +17,19 @@
#include <sfx2/frame.hxx>
#include <sfx2/sfxsids.hrc>
#include <svl/itemset.hxx>
+#include <rtl/bootstrap.hxx>
+#include <rtl/ustring.hxx>
+#include <comphelper/string.hxx>
#include <orcus/spreadsheet/import_interface.hpp>
#include <orcus/orcus_csv.hpp>
#include <orcus/orcus_gnumeric.hpp>
#include <orcus/orcus_xlsx.hpp>
#include <orcus/orcus_ods.hpp>
+#include <orcus/orcus_import_ods.hpp>
#include <orcus/global.hpp>
-
+#include <orcus/stream.hpp>
+#include <orcus/orcus_import_ods.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
#ifdef _WIN32
@@ -142,6 +147,39 @@ bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const
return true;
}
+bool ScOrcusFiltersImpl::importODS_Styles(ScDocument& rDoc, OUString& aFileName) const
+{
+ OUString aPath("$BRAND_BASE_DIR/"); /* Read the comment below before changing this */
+ rtl::Bootstrap::expandMacros(aPath);
+ OUString aValidPath;
+
+ /* The Following loop trims 'file://' from start of string and
+ * '../' from the end of string. If you ever happen to change the above macro
+ * please consider changing the following range too, otherwise app would
+ * crash!!
+ */
+ for (sal_Int32 i = 7; i < aPath.getLength() - 3; ++i)
+ aValidPath += OUString(aPath[i]);
+
+ aValidPath += aFileName;
+ OString aUrl = OUStringToOString(aValidPath, RTL_TEXTENCODING_UTF8);
+ const char* path = aUrl.getStr();
+
+ try
+ {
+ std::string content = orcus::load_file_content(path);
+ ScOrcusStyles styles(rDoc);
+ orcus::import_ods::read_styles(content.c_str(), content.size(), &styles);
+ }
+ catch (const std::exception& e)
+ {
+ SAL_WARN("sc", "Unable to load styles from xml file! " << e.what());
+ return false;
+ }
+
+ return true;
+}
+
ScOrcusXMLContext* ScOrcusFiltersImpl::createXMLContext(ScDocument& rDoc, const OUString& rPath) const
{
return new ScOrcusXMLContextImpl(rDoc, rPath);