diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2017-12-03 21:25:53 -0500 |
---|---|---|
committer | Kohei Yoshida <libreoffice@kohei.us> | 2017-12-18 02:30:39 +0100 |
commit | 152c79ee2be2374334202dc738a8f011e47845c7 (patch) | |
tree | a9dca320422e3afa66f6ed94d0ef1b0ca5899027 /sc | |
parent | 99210a149c859fcd683870b280adaeeffd1250e4 (diff) |
Initial step on enabling the orcus-based Excel 2003 XML filter.
Still some work remains in the orcus interface implementation code
in sc.
Change-Id: Idc4d95b489e8e55fbe3593557399610abe6c4ae0
Reviewed-on: https://gerrit.libreoffice.org/46655
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/orcusfilters.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/inc/orcusfiltersimpl.hxx | 1 | ||||
-rw-r--r-- | sc/source/filter/orcus/filterdetect.cxx | 12 | ||||
-rw-r--r-- | sc/source/filter/orcus/orcusfiltersimpl.cxx | 33 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 8 |
5 files changed, 54 insertions, 2 deletions
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx index e96facbaa6e3..1f96d6ac1769 100644 --- a/sc/inc/orcusfilters.hxx +++ b/sc/inc/orcusfilters.hxx @@ -31,6 +31,8 @@ public: virtual bool importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const = 0; + virtual bool importExcel2003XML(ScDocument& rDoc, SfxMedium& rMedium) const = 0; + virtual bool importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const = 0; virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const = 0; diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx index ee69df00b552..48011504fc5b 100644 --- a/sc/source/filter/inc/orcusfiltersimpl.hxx +++ b/sc/source/filter/inc/orcusfiltersimpl.hxx @@ -21,6 +21,7 @@ public: virtual bool importCSV(ScDocument& rDoc, SfxMedium& rMedium) const override; virtual bool importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const override; + virtual bool importExcel2003XML(ScDocument& rDoc, SfxMedium& rMedium) const override; virtual bool importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const override; virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const override; diff --git a/sc/source/filter/orcus/filterdetect.cxx b/sc/source/filter/orcus/filterdetect.cxx index 137585384e48..32bac167063f 100644 --- a/sc/source/filter/orcus/filterdetect.cxx +++ b/sc/source/filter/orcus/filterdetect.cxx @@ -80,8 +80,16 @@ OUString OrcusFormatDetect::detect(css::uno::Sequence<css::beans::PropertyValue> } orcus::format_t eFormat = orcus::detect(reinterpret_cast<const unsigned char*>(aContent.getStr()), aContent.getLength()); - if (eFormat == orcus::format_t::gnumeric) - return OUString("Gnumeric XML"); + + switch (eFormat) + { + case orcus::format_t::gnumeric: + return OUString("Gnumeric XML"); + case orcus::format_t::xls_xml: + return OUString("calc_MS_Excel_2003_XML"); + default: + ; + } return OUString(); } diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx index 2aa7e8b30dc0..6fc115bdce29 100644 --- a/sc/source/filter/orcus/orcusfiltersimpl.cxx +++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx @@ -25,6 +25,7 @@ #include <orcus/orcus_csv.hpp> #include <orcus/orcus_gnumeric.hpp> #include <orcus/orcus_xlsx.hpp> +#include <orcus/orcus_xls_xml.hpp> #include <orcus/orcus_ods.hpp> #include <orcus/orcus_import_ods.hpp> #include <orcus/global.hpp> @@ -115,6 +116,38 @@ bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) co return true; } +bool ScOrcusFiltersImpl::importExcel2003XML(ScDocument& rDoc, SfxMedium& rMedium) const +{ + ScOrcusFactory aFactory(rDoc); + aFactory.setStatusIndicator(getStatusIndicator(rMedium)); + SvStream* pStream = rMedium.GetInStream(); + pStream->Seek(0); + static const size_t nReadBuffer = 1024*32; + OStringBuffer aBuffer((int(nReadBuffer))); + size_t nRead = 0; + do + { + char pData[nReadBuffer]; + nRead = pStream->ReadBytes(pData, nReadBuffer); + aBuffer.append(static_cast<sal_Char*>(pData), nRead); + } + while (nRead == nReadBuffer); + + try + { + rDoc.ClearTabs(); + orcus::orcus_xls_xml filter(&aFactory); + filter.read_stream(aBuffer.getStr(), aBuffer.getLength()); + } + catch (const std::exception& e) + { + SAL_WARN("sc", "Unable to load Excel 2003 XML file! " << e.what()); + return false; + } + + return true; +} + bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const { ScOrcusFactory aFactory(rDoc); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 98e3e5b51eaa..6f1ba210ff4b 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1169,6 +1169,14 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) bRet = pOrcus->importGnumeric(aDocument, rMedium); } + else if (aFltName == "MS Excel 2003 XML Orcus") + { + ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters(); + if (!pOrcus) + return false; + + bRet = pOrcus->importExcel2003XML(aDocument, rMedium); + } else if (aFltName == pFilterAscii) { SfxItemSet* pSet = rMedium.GetItemSet(); |