add xlsx support to fftester

Change-Id: I07198f24a3e096fab67333cf6a98185d5b40fffc
Reviewed-on: https://gerrit.libreoffice.org/45399
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2017-11-28 10:18:34 +00:00
parent 97dabf63f6
commit f6a2c667d1
2 changed files with 60 additions and 0 deletions

View file

@ -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: */

View file

@ -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);