[Libreoffice-commits] core.git: Branch 'private/kohei/excel-2003-xml-orcus-filter' - 2 commits - sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Fri Dec 8 02:38:47 UTC 2017


 sc/source/filter/orcus/orcusfiltersimpl.cxx |  121 +++++++---------------------
 1 file changed, 34 insertions(+), 87 deletions(-)

New commits:
commit 2649c42b657fe16bd3d6645ca3b3dd8f320156bc
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Dec 7 21:34:40 2017 -0500

    All the other orcus-based filters should take the same code path.
    
    Change-Id: Iac96c6eb842a769d70c3f39830cbdb0e1ee93dc8

diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 1773caa22330..fbbdd0b64e53 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -96,21 +96,9 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, SfxMedium& rMedium) const
 {
     ScOrcusFactory aFactory(rDoc);
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
-    OString aSysPath = toSystemPath(rMedium.GetName());
-    const char* path = aSysPath.getStr();
 
-    try
-    {
-        orcus::orcus_csv filter(&aFactory);
-        filter.read_file(path);
-    }
-    catch (const std::exception&)
-    {
-        rDoc.InsertTab(SC_TAB_APPEND, "Foo");
-        rDoc.SetString(0, 0, 0, "Failed to load!!!");
-        return false;
-    }
-    return true;
+    orcus::orcus_csv filter(&aFactory);
+    return loadFileContent(rDoc, rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const
@@ -135,42 +123,18 @@ bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const
 {
     ScOrcusFactory aFactory(rDoc);
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
-    OString aSysPath = toSystemPath(rMedium.GetName());
-    const char* path = aSysPath.getStr();
-
-    try
-    {
-        orcus::orcus_xlsx filter(&aFactory);
-        filter.read_file(path);
-    }
-    catch (const std::exception& e)
-    {
-        SAL_WARN("sc", "Unable to load xlsx file! " << e.what());
-        return false;
-    }
 
-    return true;
+    orcus::orcus_xlsx filter(&aFactory);
+    return loadFileContent(rDoc, rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const
 {
     ScOrcusFactory aFactory(rDoc);
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
-    OString aSysPath = toSystemPath(rMedium.GetName());
-    const char* path = aSysPath.getStr();
-
-    try
-    {
-        orcus::orcus_ods filter(&aFactory);
-        filter.read_file(path);
-    }
-    catch (const std::exception& e)
-    {
-        SAL_WARN("sc", "Unable to load ods file! " << e.what());
-        return false;
-    }
 
-    return true;
+    orcus::orcus_ods filter(&aFactory);
+    return loadFileContent(rDoc, rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importODS_Styles(ScDocument& rDoc, OUString& aPath) const
commit b5cfd3584b94e4562ac77d30e9fe3b0ba8cb6b3e
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Dec 7 21:27:20 2017 -0500

    Remove code duplicates.
    
    Change-Id: I424e5999ef2ec6e71f6b6361ed91079b8d949555

diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 6fc115bdce29..1773caa22330 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -55,6 +55,35 @@ uno::Reference<task::XStatusIndicator> getStatusIndicator(const SfxMedium& rMedi
     return xStatusIndicator;
 }
 
+bool loadFileContent(ScDocument& rDoc, SfxMedium& rMedium, orcus::iface::import_filter& filter)
+{
+    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();
+        filter.read_stream(aBuffer.getStr(), aBuffer.getLength());
+    }
+    catch (const std::exception& e)
+    {
+        SAL_WARN("sc", "Unable to load file via orcus filter! " << e.what());
+        return false;
+    }
+
+    return true;
+}
+
 }
 
 OString ScOrcusFiltersImpl::toSystemPath(const OUString& rPath)
@@ -88,64 +117,18 @@ bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) co
 {
     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_gnumeric filter(&aFactory);
-        filter.read_stream(aBuffer.getStr(), aBuffer.getLength());
-    }
-    catch (const std::exception& e)
-    {
-        SAL_WARN("sc", "Unable to load gnumeric file! " << e.what());
-        return false;
-    }
 
-    return true;
+    orcus::orcus_gnumeric filter(&aFactory);
+    return loadFileContent(rDoc, rMedium, filter);
 }
 
 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;
+    orcus::orcus_xls_xml filter(&aFactory);
+    return loadFileContent(rDoc, rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const


More information about the Libreoffice-commits mailing list