[Libreoffice-commits] core.git: sc/source vcl/workben

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 22 07:58:20 UTC 2021


 sc/source/ui/docshell/docsh.cxx |   42 ++++++++++++++++++++++++++++++++++++++++
 sc/source/ui/inc/docsh.hxx      |    4 +++
 vcl/workben/fftester.cxx        |   10 +++++++++
 3 files changed, 56 insertions(+)

New commits:
commit 7f5af8272d8b10bf56b82cbe9d898e8ed0a347ca
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Sep 21 20:51:51 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Sep 22 09:57:41 2021 +0200

    add a TestImportDBF
    
    Change-Id: Iddb0d69d2ffaafd81076cd52a8424c32fe3c4114
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122408
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index d6bb0d9f5f6f..baf0903ca855 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -121,6 +121,7 @@
 #include <comphelper/processfactory.hxx>
 #include <comphelper/string.hxx>
 #include <unotools/configmgr.hxx>
+#include <unotools/tempfile.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <uiitems.hxx>
 #include <dpobject.hxx>
@@ -3404,4 +3405,45 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportSLK(SvStream &rStream)
     return aImpEx.ImportStream(rStream, OUString(), SotClipboardFormatId::SYLK);
 }
 
+extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDBF(SvStream &rStream)
+{
+    ScDLL::Init();
+
+    utl::TempFile aTempInput;
+    aTempInput.EnableKillingFile();
+
+    // need a real file for this filter
+    SvStream* pInputStream = aTempInput.GetStream(StreamMode::WRITE);
+    sal_uInt8 aBuffer[8192];
+    while (auto nRead = rStream.ReadBytes(aBuffer, SAL_N_ELEMENTS(aBuffer)))
+        pInputStream->WriteBytes(aBuffer, nRead);
+    aTempInput.CloseStream();
+
+    SfxMedium aMedium(aTempInput.GetURL(), StreamMode::STD_READWRITE);
+
+    ScDocShellRef xDocShell = new ScDocShell(SfxModelFlags::EMBEDDED_OBJECT |
+                                             SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
+                                             SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+
+    xDocShell->DoInitNew();
+
+    ScDocument& rDoc = xDocShell->GetDocument();
+
+    ScDocOptions aDocOpt = rDoc.GetDocOptions();
+    aDocOpt.SetLookUpColRowNames(false);
+    rDoc.SetDocOptions(aDocOpt);
+    rDoc.MakeTable(0);
+    rDoc.EnableExecuteLink(false);
+    rDoc.SetInsertingFromOtherDoc(true);
+
+    ScDocRowHeightUpdater::TabRanges aRecalcRanges(0, rDoc.MaxRow());
+    std::map<SCCOL, ScColWidthParam> aColWidthParam;
+    ErrCode eError = xDocShell->DBaseImport(aMedium.GetPhysicalName(), RTL_TEXTENCODING_IBM_850, aColWidthParam, aRecalcRanges.maRanges);
+
+    xDocShell->DoClose();
+    xDocShell.clear();
+
+    return eError == ERRCODE_NONE;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 8c353d0087c7..635db201ac97 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -70,6 +70,8 @@ typedef std::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
 
 enum class LOKCommentNotificationType { Add, Modify, Remove };
 
+extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDBF(SvStream &rStream);
+
                                     // Extra flags for Repaint
 #define SC_PF_LINES         1
 #define SC_PF_TESTMERGE     2
@@ -133,6 +135,8 @@ class SC_DLLPUBLIC ScDocShell final: public SfxObjectShell, public SfxListener
     SAL_DLLPRIVATE bool          SaveXML( SfxMedium* pMedium, const css::uno::Reference< css::embed::XStorage >& );
     SAL_DLLPRIVATE SCTAB         GetSaveTab();
 
+    friend bool TestImportDBF(SvStream &rStream);
+
     SAL_DLLPRIVATE ErrCode       DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
                                              std::map<SCCOL, ScColWidthParam>& aColWidthParam, ScFlatBoolRowSegments& rRowHeightsRecalc );
     SAL_DLLPRIVATE ErrCode       DBaseExport(
diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx
index 4359452f39ac..f700b0660f0f 100644
--- a/vcl/workben/fftester.cxx
+++ b/vcl/workben/fftester.cxx
@@ -444,6 +444,16 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
             SvFileStream aFileStream(out, StreamMode::READ);
             ret = static_cast<int>((*pfnImport)(aFileStream));
         }
+        else if (strcmp(argv[2], "dbf") == 0)
+        {
+            static FFilterCall pfnImport(nullptr);
+            if (!pfnImport)
+            {
+                pfnImport = load(u"libsclo.so", "TestImportDBF");
+            }
+            SvFileStream aFileStream(out, StreamMode::READ);
+            ret = static_cast<int>((*pfnImport)(aFileStream));
+        }
         else if (strcmp(argv[2], "dif") == 0)
         {
             static FFilterCall pfnImport(nullptr);


More information about the Libreoffice-commits mailing list