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

Caolán McNamara caolanm at redhat.com
Tue Nov 28 16:54:22 UTC 2017


 sc/source/filter/xml/xmlimprt.cxx |   46 ++++++++++++++++++++++++++++++++++++++
 vcl/workben/fftester.cxx          |   14 +++++++++++
 2 files changed, 60 insertions(+)

New commits:
commit f6a2c667d19bb199a97a5822ab718758df421e7f
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Nov 28 10:18:34 2017 +0000

    add xlsx support to fftester
    
    Change-Id: I07198f24a3e096fab67333cf6a98185d5b40fffc
    Reviewed-on: https://gerrit.libreoffice.org/45399
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 1bf8d576fe38..e0795f56808d 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -82,6 +82,8 @@
 
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/io/IOException.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
 #include <com/sun/star/sheet/XSheetCellRange.hpp>
 #include <com/sun/star/document/XActionLockable.hpp>
 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
@@ -2102,4 +2104,48 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportFODS(SvStream &rStream)
     return ret;
 }
 
+extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL TestImportXLSX(SvStream &rStream)
+{
+    ScDLL::Init();
+
+    SfxObjectShellLock xDocSh(new ScDocShell);
+    xDocSh->DoInitNew();
+    uno::Reference<frame::XModel> xModel(xDocSh->GetModel());
+
+    uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
+    uno::Reference<io::XInputStream> xStream(new utl::OSeekableInputStreamWrapper(rStream));
+
+    uno::Reference<document::XFilter> xFilter(xMultiServiceFactory->createInstance("com.sun.star.comp.oox.xls.ExcelFilter"), uno::UNO_QUERY_THROW);
+
+    uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW);
+    uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
+    {
+        { "InputStream", uno::makeAny(xStream) },
+        { "InputMode", uno::makeAny(true) },
+    }));
+    xImporter->setTargetDocument(xModel);
+
+    //SetLoading hack because the document properties will be re-initted
+    //by the xml filter and during the init, while its considered uninitialized,
+    //setting a property will inform the document its modified, which attempts
+    //to update the properties, which throws cause the properties are uninitialized
+    xDocSh->SetLoading(SfxLoadedFlags::NONE);
+    bool ret = false;
+    try
+    {
+        ret = xFilter->filter(aArgs);
+    }
+    catch (const css::io::IOException&)
+    {
+    }
+    catch (const css::lang::WrappedTargetRuntimeException&)
+    {
+    }
+    xDocSh->SetLoading(SfxLoadedFlags::ALL);
+
+    xDocSh->DoClose();
+
+    return ret;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/workben/fftester.cxx b/vcl/workben/fftester.cxx
index 591a28589022..7e78903a625f 100644
--- a/vcl/workben/fftester.cxx
+++ b/vcl/workben/fftester.cxx
@@ -417,6 +417,20 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
             SvFileStream aFileStream(out, StreamMode::READ);
             ret = (int) (*pfnImport)(aFileStream);
         }
+        else if (strcmp(argv[2], "xlsx") == 0)
+        {
+            static FFilterCall pfnImport(nullptr);
+            if (!pfnImport)
+            {
+                osl::Module aLibrary;
+                aLibrary.loadRelative(&thisModule, "libsclo.so", SAL_LOADMODULE_LAZY);
+                pfnImport = reinterpret_cast<FFilterCall>(
+                    aLibrary.getFunctionSymbol("TestImportXLSX"));
+                aLibrary.release();
+            }
+            SvFileStream aFileStream(out, StreamMode::READ);
+            ret = (int) (*pfnImport)(aFileStream);
+        }
         else if (strcmp(argv[2], "fodp") == 0)
         {
             static FFilterCall pfnImport(nullptr);


More information about the Libreoffice-commits mailing list