From f6a2c667d19bb199a97a5822ab718758df421e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 28 Nov 2017 10:18:34 +0000 Subject: [PATCH] add xlsx support to fftester MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I07198f24a3e096fab67333cf6a98185d5b40fffc Reviewed-on: https://gerrit.libreoffice.org/45399 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sc/source/filter/xml/xmlimprt.cxx | 46 +++++++++++++++++++++++++++++++ vcl/workben/fftester.cxx | 14 ++++++++++ 2 files changed, 60 insertions(+) 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 #include +#include +#include #include #include #include @@ -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 xModel(xDocSh->GetModel()); + + uno::Reference xMultiServiceFactory(comphelper::getProcessServiceFactory()); + uno::Reference xStream(new utl::OSeekableInputStreamWrapper(rStream)); + + uno::Reference xFilter(xMultiServiceFactory->createInstance("com.sun.star.comp.oox.xls.ExcelFilter"), uno::UNO_QUERY_THROW); + + uno::Reference xImporter(xFilter, uno::UNO_QUERY_THROW); + uno::Sequence 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( + 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);