[Libreoffice-commits] core.git: 3 commits - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Dec 18 01:37:48 UTC 2017


 sc/inc/documentimport.hxx                   |    1 
 sc/source/core/data/documentimport.cxx      |    5 +
 sc/source/filter/orcus/interface.cxx        |   12 ++
 sc/source/filter/orcus/orcusfiltersimpl.cxx |  122 +++++++---------------------
 4 files changed, 51 insertions(+), 89 deletions(-)

New commits:
commit 599a23b17818bbeea85b6ab0b57401e4ff2cd5c0
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Dec 7 21:58:16 2017 -0500

    Take into account the fact that ScDocument already has one sheet.
    
    ScDocument already has one sheet upon creation, so we need to avoid
    appending sheet when the request is for the first sheet.
    
    Change-Id: Ie5526d6791e545f5faa0bf3f16988351c09e94c8
    Reviewed-on: https://gerrit.libreoffice.org/46658
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx
index 00496cdaac2b..03f415c381cc 100644
--- a/sc/inc/documentimport.hxx
+++ b/sc/inc/documentimport.hxx
@@ -87,6 +87,7 @@ public:
     SCTAB getSheetIndex(const OUString& rName) const;
     SCTAB getSheetCount() const;
     bool appendSheet(const OUString& rName);
+    void setSheetName(SCTAB nTab, const OUString& rName);
 
     void setOriginDate(sal_uInt16 nYear, sal_uInt16 nMonth, sal_uInt16 nDay);
 
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index c46f1b09c95d..c41e134558bf 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -167,6 +167,11 @@ bool ScDocumentImport::appendSheet(const OUString& rName)
     return true;
 }
 
+void ScDocumentImport::setSheetName(SCTAB nTab, const OUString& rName)
+{
+    mpImpl->mrDoc.SetTabNameOnLoad(nTab, rName);
+}
+
 void ScDocumentImport::setOriginDate(sal_uInt16 nYear, sal_uInt16 nMonth, sal_uInt16 nDay)
 {
     if (!mpImpl->mrDoc.pDocOptions)
diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
index 4a2f5567f583..eff9570e66c3 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -85,9 +85,19 @@ ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) :
     mnProgress(0) {}
 
 orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(
-    orcus::spreadsheet::sheet_t /*sheet_index*/, const char* sheet_name, size_t sheet_name_length)
+    orcus::spreadsheet::sheet_t sheet_index, const char* sheet_name, size_t sheet_name_length)
 {
     OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
+
+    if (sheet_index == 0)
+    {
+        // The calc document initializes with one sheet already present.
+        assert(maDoc.getSheetCount() == 1);
+        maDoc.setSheetName(0, aTabName);
+        maSheets.push_back(o3tl::make_unique<ScOrcusSheet>(maDoc, 0, *this));
+        return maSheets.back().get();
+    }
+
     if (!maDoc.appendSheet(aTabName))
         return nullptr;
 
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index fbbdd0b64e53..8683749fdd7c 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -55,7 +55,7 @@ uno::Reference<task::XStatusIndicator> getStatusIndicator(const SfxMedium& rMedi
     return xStatusIndicator;
 }
 
-bool loadFileContent(ScDocument& rDoc, SfxMedium& rMedium, orcus::iface::import_filter& filter)
+bool loadFileContent(SfxMedium& rMedium, orcus::iface::import_filter& filter)
 {
     SvStream* pStream = rMedium.GetInStream();
     pStream->Seek(0);
@@ -72,7 +72,6 @@ bool loadFileContent(ScDocument& rDoc, SfxMedium& rMedium, orcus::iface::import_
 
     try
     {
-        rDoc.ClearTabs();
         filter.read_stream(aBuffer.getStr(), aBuffer.getLength());
     }
     catch (const std::exception& e)
@@ -98,7 +97,7 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, SfxMedium& rMedium) const
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
 
     orcus::orcus_csv filter(&aFactory);
-    return loadFileContent(rDoc, rMedium, filter);
+    return loadFileContent(rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const
@@ -107,7 +106,7 @@ bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) co
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
 
     orcus::orcus_gnumeric filter(&aFactory);
-    return loadFileContent(rDoc, rMedium, filter);
+    return loadFileContent(rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importExcel2003XML(ScDocument& rDoc, SfxMedium& rMedium) const
@@ -116,7 +115,7 @@ bool ScOrcusFiltersImpl::importExcel2003XML(ScDocument& rDoc, SfxMedium& rMedium
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
 
     orcus::orcus_xls_xml filter(&aFactory);
-    return loadFileContent(rDoc, rMedium, filter);
+    return loadFileContent(rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const
@@ -125,7 +124,7 @@ bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
 
     orcus::orcus_xlsx filter(&aFactory);
-    return loadFileContent(rDoc, rMedium, filter);
+    return loadFileContent(rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const
@@ -134,7 +133,7 @@ bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const
     aFactory.setStatusIndicator(getStatusIndicator(rMedium));
 
     orcus::orcus_ods filter(&aFactory);
-    return loadFileContent(rDoc, rMedium, filter);
+    return loadFileContent(rMedium, filter);
 }
 
 bool ScOrcusFiltersImpl::importODS_Styles(ScDocument& rDoc, OUString& aPath) const
commit d0197ae70a31e02f7ec3c251745470024b287418
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
    Reviewed-on: https://gerrit.libreoffice.org/46657
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>
    Tested-by: Kohei Yoshida <libreoffice at kohei.us>

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 ca1a583e96f832797bf638d0b0a37840d35af5f9
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Dec 7 21:27:20 2017 -0500

    Remove code duplicates.
    
    Change-Id: I424e5999ef2ec6e71f6b6361ed91079b8d949555
    Reviewed-on: https://gerrit.libreoffice.org/46656
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>

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