diff options
author | Jaskaran Singh <jvsg1303@gmail.com> | 2016-07-12 17:32:19 +0530 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-09-18 00:15:11 +0200 |
commit | 2aea6d519ff7e487af0b2a39d78e00c0227799af (patch) | |
tree | 9cf0bed66193d96055c878bd844702ce0ceb430d /sc | |
parent | 7911f21cd3e0deb6c1966dc97b8a5e5cf994d3af (diff) |
Add a method to import ODF styles via orcus
Change-Id: Id76593bbb9982ec6745737ade800ae669e8e4471
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/orcusfilters.hxx | 6 | ||||
-rw-r--r-- | sc/source/filter/inc/orcusfiltersimpl.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/orcus/orcusfiltersimpl.cxx | 40 |
3 files changed, 47 insertions, 1 deletions
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx index 58e6fcb18361..e96facbaa6e3 100644 --- a/sc/inc/orcusfilters.hxx +++ b/sc/inc/orcusfilters.hxx @@ -36,6 +36,12 @@ public: virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const = 0; /** + * Used to import just the styles from an xml file. + */ + + virtual bool importODS_Styles(ScDocument& rDoc, OUString& aFileName) const = 0; + + /** * Create a context for XML file. The context object stores session * information for each unique XML file. You must create a new context * for each XML file, and never to re-use the same context for multiple diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx index 47f88f3e3f9a..d0d40f8a1843 100644 --- a/sc/source/filter/inc/orcusfiltersimpl.hxx +++ b/sc/source/filter/inc/orcusfiltersimpl.hxx @@ -25,6 +25,8 @@ public: virtual bool importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const override; virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const override; + virtual bool importODS_Styles(ScDocument& rDoc, OUString& aFileName) const override; + virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const OUString& rPath) const override; }; 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); |